Last active
July 25, 2016 07:16
-
-
Save mobynote/61f15a43237b6c73b607630ee8f02a39 to your computer and use it in GitHub Desktop.
JQuery v1.11.3中attr()设置checkbox选中状态无效,应该使用prop()替换attr()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<input type="checkbox" id="cbtn_all"> 全选/取消全选 | |
<input type="checkbox" name="cbtn_id">A | |
<input type="checkbox" name="cbtn_id">B | |
<input type="checkbox" name="cbtn_id">C | |
// 全选按钮,控制其它复选框 | |
$(function (){ | |
$('#cbtn_all').click(function(){ | |
if(this.checked){ | |
$(':checkbox[name="cbtn_id"]').prop("checked", true); | |
}else{ | |
$(':checkbox[name="cbtn_id"]').prop("checked", false); | |
} | |
}); | |
$(':checkbox[name="cbtn_id"]').click(function () { | |
allchk(); | |
}) | |
}); | |
//复选框,控制全选复选框 | |
function allchk() { | |
var cb_total = $(':checkbox[name="cbtn_id"]').size(); | |
var cb_num = 0; | |
$(':checkbox[name="cbtn_id"]').each(function () { | |
if($(this).prop("checked") == true){ | |
cb_num ++; | |
} | |
}); | |
if(cb_total == cb_num){ | |
$('#cbtn_all').prop("checked", true); | |
}else{ | |
$('#cbtn_all').prop("checked", false); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment