jQuery和IE:检查隐藏的输入“checked”-attribute不起作用
我一直试图检查我的输入[type = hidden]是否有checked =“checked”属性。 该输入字段如下所示:
在Firefox中,通过使用它可以正常工作:
jQuery(selector).find('input[name=1_WILLINFOS]').attr('checked') == "checked"
但IE10总是给我一个假的。
到现在为止我尝试使用以下内容:
.attr("checked") == "checked" .attr("checked") == true .is(':checked')
所有这些都给了我一个假的。
有任何想法吗? 谢谢
您不能将隐藏输入作为复选框,因此它不具有已checked
属性。 您可以使用type="checkbox"
并使用display:none
隐藏它,如果您需要它是一个复选框,或者您只需使用0
或1
的隐藏输入来模拟它。
您可以使用任何属性隐藏元素。 例如
//is an `input` type `hidden` with attribute abc having value xyz
在你的情况下,
//is an `input` type `hidden` with `attribute` checked with value `checked` $('input[name=1_WILLINFOS]').attr('checked') == "checked" //is an element with name '1_WILLINFOS' and attribute checked set to 'checked' .So it will surely match and return true
但,
.attr("checked") == true //will fail as you set `checked` attribute value to 'checked' and your are checked for true condition.so you must check for `.attr("checked") == 'checked` $('input[name=1_WILLINFOS]').is(':checked'));// will check for attribute checked if its set it will return you true.
这是你的小提琴