【问题标题】:IE not selecting form field when label is clicked an form field is hidden单击标签时 IE 未选择表单字段 表单字段被隐藏
【发布时间】:2010-02-09 14:41:46
【问题描述】:

我正在使用 jQuery 来隐藏表单字段(我正在操作复选框和单选按钮)。

在 FF 和 Chrome 中,当我单击关联的标签时,表单字段仍会激活并检查。在 IE 中,这不会发生。

如何让标签激活 IE 中的复选框/单选按钮?

【问题讨论】:

标签: javascript jquery html internet-explorer


【解决方案1】:

我以前也经历过。最好将隐藏的字段移出屏幕而不是隐藏它们。

事实上,我确实在 SO 上问过这个问题:

IE - hidden radio button not checked when the corresponding label is clicked

【讨论】:

    【解决方案2】:

    你是怎么隐藏的?您可能需要通过一些激进的 css 将其移出屏幕:

    .hidden { position:relative; left: -10000 }
    

    然后切换.hidden 类以显示/隐藏元素。

    【讨论】:

      【解决方案3】:

      我也遇到过。 IE 不会改变隐藏表单域的值。您必须先取消隐藏它们。可能最简单的方法是向所有允许具有隐藏表单字段的标签添加 onclick 操作。比如:

      $("label.hideablefield").live('click', function(){
        var fid = $(this).attr('for');
        $('#'+ fid).show();
        $('#'+ fid).select(); //or maybe .focus, I'm not sure 
      });
      

      显然,这只会打开该字段。您需要为重新隐藏/取消选择设置一个切换条件。

      【讨论】:

        猜你喜欢
        • 2021-12-20
        • 2012-08-12
        • 2010-11-18
        • 1970-01-01
        • 2017-03-08
        • 2019-05-19
        • 2020-12-17
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多