【问题标题】:jquery checks randomly the checkboxjquery 随机检查复选框
【发布时间】:2013-04-22 15:59:02
【问题描述】:

这个复选框控制器有什么问题?
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/

【问题讨论】:

    标签: jquery html checkbox


    【解决方案1】:

    改用prop:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-23
      • 1970-01-01
      • 1970-01-01
      • 2014-04-26
      • 2013-02-02
      相关资源
      最近更新 更多