4

这个复选框控制器有什么问题?
Jquery 更改 html 中的属性,但不更改图形复选框...

html

<input type="checkbox" checked="checked"/>
<input type="checkbox"/>
<a href="#" class="no">off</a>
<a href="#" class="yes">on</a>

js

$(document).ready(function(){
$('.yes').click(function(){
    $('input:checkbox').attr('checked','checked');
});
 $('.no').click(function(){
     $('input:checkbox').removeAttr('checked');
});
})

考试

http://jsfiddle.net/ehijon/Jmn3r/

4

1 回答 1

4

更改为使用道具:

$("input[type='checkbox']").prop('checked',true); // --Change to false to uncheck

见小提琴更新:http: //jsfiddle.net/Jmn3r/1/

于 2013-04-22T16:00:17.973 回答