Internet Explorer(和jquery)中的标签和隐藏字段 [英] Labels and hidden fields in Internet Explorer (and jquery)

查看:227
本文介绍了Internet Explorer(和jquery)中的标签和隐藏字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法在IE中检查隐藏的复选框。这是基本html:

I'm having trouble checking hidden checkboxes in IE. This is the base html:

<input id="groups_ids_1" name="group_ids[]" type="checkbox" value="1" />
<label for="groups_ids_1">Display</label>

这个工作正常,但如果我然后隐藏复选框使用

This works fine, but if I then hide the checkboxes using either

$('input[type=checkbox]').hide();

$('input[type=checkbox]').css('visibility', 'hidden');

点击标签不再检查IE中的复选框。当然,它可以在Firefox,Chrome和Safari中正常工作。

Clicking the label no longer checks the checkbox in IE. Of course it works fine in Firefox, Chrome and Safari.

推荐答案

您可以尝试添加一个onclick IE的问题。

You could try added an onclick to the label to get around the IE issues.

$('label').click(function() {
  $('#' + $(this).attr('for')).click();
});

如果不起作用,请尝试手动设置属性。

If that does not work, try setting the attribute manually.

$('label').click(function() {
  var checkbox = $('#' + $(this).attr('for'));
  if (checkbox.is(':checked')) {
    checkbox.removeAttr('checked');
  } else {
    checkbox.attr('checked', 'checked');
  }
});

这篇关于Internet Explorer(和jquery)中的标签和隐藏字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆