首页 > 其他 > 详细

Toggle Checkboxes on/off

时间:2017-06-18 15:37:09      阅读:277      评论:0      收藏:0      [点我收藏+]

You can write:

$(document).ready(function() {
    $("#select-all-teammembers").click(function() {
        var checkBoxes = $("input[name=recipients\\[\\]]");
        checkBoxes.prop("checked", !checkBoxes.prop("checked"));
    });                 
});

Before jQuery 1.6, when we only had attr() and not prop(), we used to write:

checkBoxes.attr("checked", !checkBoxes.attr("checked"));

But prop() has better semantics than attr() when applied to "boolean" HTML attributes, so it is usually preferred in this situation.

 

 

ref: https://stackoverflow.com/questions/4177159/toggle-checkboxes-on-off

Toggle Checkboxes on/off

原文:http://www.cnblogs.com/pinganzi/p/7044308.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!