我改变复选框状态是这样的:$(this).attr("checked", 'checked');
jQuery的接收复选框状态
这个我想收到复选框状态后,但我得到了这一点:
$(this).attr('checked'): "checked"
$(this).is(':checked'): false
这怎么可能呢?
P.S.也许我没有正确改变通过jQuery的复选框状态?
我改变复选框状态是这样的:$(this).attr("checked", 'checked');
jQuery的接收复选框状态
这个我想收到复选框状态后,但我得到了这一点:
$(this).attr('checked'): "checked"
$(this).is(':checked'): false
这怎么可能呢?
P.S.也许我没有正确改变通过jQuery的复选框状态?
正确的方法是$(this).prop('checked')
返回布尔型属性而不是属性(它是一个字符串)。
使用.prop()
你也可以设置的选中状态:$(this).prop('checked', true_or_false);
正如你可以看到http://jsfiddle.net/ThiefMaster/QR2fL/,.attr('checked')
返回属性的初始值 - 选中/取消选中该复选框时,它不会改变。
你不应该检查类似这样的复选框:
$(this).attr("checked", 'checked');
但像他这样
$(this).prop("checked", true);
要检查复选框被选中,你可以使用:
$(this).prop('checked');
或
$(this).is(':checked');
哪个返回布尔型proerty