Attributes vs. Properties
attributes和properties之间的差异在特定情况下是很重要。jQuery
1.6之前 ,.attr()方法在取某些
attribute 的值时,会返回 property 的值,这就导致了结果的不一致。从 jQuery 1.6 开始, .prop()方法
方法返回 property 的值,而.attr() 方法返回 attributes 的值。
例如, ***edIndex, tagName, nodeName, nodeType, ownerDocument, defaultChecked,
和 defaultSelected应使用.prop()方法进行取值或赋值。 在jQuery1.6之前,这些属性使用.attr()方法取得,但是这并不是元素的attr属性。他们没有相应的属性(attributes),只有特性(property)。
$(".checkbox input[type=checkbox]").attr("checked",true);
修改为
$(".checkbox input[type=checkbox]").prop("checked",true);