jQuery版本升级, 大于1.6.1之后,
$("#element").attr("checked", true)
能够设置#element的attr有checked,
但是设置$("#element").attr("checked", false)
,
再调用$("#element").attr("checked")
的返回值为undifined
根据官方文档:
jQuery 1.6.1 Released
Attribute/Property | .attr() | .prop() |
---|---|---|
accesskey | ✓ | |
align | ✓ | |
async | ✓ | ✓ |
autofocus | ✓ | ✓ |
checked | ✓ | ✓ |
class | ✓ | |
contenteditable | ✓ | |
defaultValue | ✓ | |
draggable | ✓ | |
href | ✓ | |
id | ✓ | |
label | ✓ | |
location * | ✓ | ✓ |
multiple | ✓ | ✓ |
nodeName | ✓ | |
nodeType | ✓ | |
readOnly | ✓ | ✓ |
rel | ✓ | |
selected | ✓ | ✓ |
selectedindex | ✓ | |
src | ✓ | |
style | ✓ | |
tabindex | ✓ | |
tagName | ✓ | |
title | ✓ | |
type | ✓ | |
width ** | ✓ |
可以发现checked应该使用prop, 即:
$("#element").prop("checked", false)
$("#element").prop("checked")