您的位置:首页 > Web前端 > JQuery

Jquery 全选、反选

2015-11-02 08:49 417 查看
jQuery 1.9以后用 prop(); 不用attr 等

$(function() {
$('#inputCheck').click(function() {
$("input[name='Checkbox1']").prop("checked", $(this).prop("checked"));
});
}); // 全选

$(function() {
$("#select_reverse").click(function() {
$("input[name='Checkbox1']").each(function(idx, item) {
$(item).prop("checked", !$(item).prop("checked"));
})
});
});//反选


<input id="inputCheck" type="checkbox" />全选
<input id="select_reverse" type="checkbox" />反选
<input name="Checkbox1" type="checkbox" />
<input name="Checkbox1" type="checkbox" />
<input name="Checkbox1" type="checkbox" />
<input name="Checkbox1" type="checkbox" />
<input name="Checkbox1" type="checkbox" />
<input name="Checkbox1" type="checkbox" />
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: