标签:jquery
为了方便描述,将问题简化如下:<form>
<input type="checkbox">iqiyi</input>
<input type="checkbox" checked="checked">letv</input>
</form>
<button type>showStatus</button>
<script>
$("button").click(function(){
var list = $("form input");
for (var i=0; i<list.length; i++){
console.log('input ' + i + ':' + $(list[i]).attr('checked'));
}
})
</script>input 0:undefined input 1:checked看起来没啥问题。
input 0:undefined input 1:checked居然没有变化!what‘s wrong!莫非jquery的attr有bug!?
input 0:false input 1:true input 0:true input 1:false当checkedbox被勾选,得到true,未被选得到false,会随用户操作动态变化。true,false的返回值也更易使用。
| Attribute/Property |
.attr() |
.prop() |
|---|---|---|
| accesskey | √ |
|
| align | √ |
|
| async |
|
√ |
| autofocus |
|
√ |
| checked |
|
√ |
| class | √ |
|
| contenteditable | √ |
|
| draggable | √ |
|
| href | √ |
|
| id | √ |
|
| label | √ |
|
| location ( i.e. window.location ) |
|
√ |
| multiple |
|
√ |
| readOnly |
|
√ |
| rel | √ |
|
| selected |
|
√ |
| src | √ |
|
| tabindex | √ |
|
| title | √ |
|
| type | √ |
|
width ( if needed over .width() ) |
√ |
标签:jquery
原文地址:http://blog.csdn.net/qmhball/article/details/44975753