Skip to content

Instantly share code, notes, and snippets.

@emojiijome
Created May 21, 2015 07:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emojiijome/7100d5eb0f01c41bda69 to your computer and use it in GitHub Desktop.
Save emojiijome/7100d5eb0f01c41bda69 to your computer and use it in GitHub Desktop.
$(function () {
//全不选
$("#btnAllNotChk").click(function () {
$("#chk input:checkbox").removeAttr("checked");
});
//全选
$("#btnAllChk").click(function () {
$("#chk input:checkbox").attr("checked", "checked");
});
//反选
$("#btnInvert").click(function () {
//1.方法一实现反选
$("#chk input:checkbox").each(function () {
this.checked = !this.checked;
})
//2.方法二实现反选
// $("#chk input:checkbox").each(function (){
// if ($(this).attr("checked")) {
// $(this).attr("checked", false);
// }
// else {
// $(this).attr("checked", "checked");
// }
// })
//3.方法三实现反选
// var $cks = $("#chk input:checkbox");
// for (var i = 0; i < $cks.length; i++) {
// $cks.get(i).checked = !$cks.get(i).checked;
// }
});
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment