jQuery CheckBox全选
?
$(function(){$('#inputChkAll').click(function(){$("input[name='chkJob']").attr("checked", $(this).attr("checked"));//注意此處}); });代碼如上,#inputChkAll用來全選或者全不選的CheckBox控件,其控制了name='chkJob'這個復選組。根據inputChkAll的勾選狀態$(this).attr("checked")來這是chkJob的勾選狀態
?
? // 全選
??????????? $("#btnCheckAll").bind("click", function () {
??????????????? $("[name = chkItem]:checkbox").attr("checked", true);
??????????? });
??????????? // 全不選
??????????? $("#btnCheckNone").bind("click", function () {
??????????????? $("[name = chkItem]:checkbox").attr("checked", false);
??????????? });
??????????? // 反選
??????????? $("#btnCheckReverse").bind("click", function () {
??????????????? $("[name = chkItem]:checkbox").each(function () {
??????????????????? $(this).attr("checked", !$(this).attr("checked"));
??????????????? });
??????????? });
??????????? // 得到選中
??????????? $("#btnSubmit").bind("click", function () {
??????????????? var result = new Array();
??????????????? $("[name = chkItem]:checkbox").each(function () {
??????????????????? if ($(this).is(":checked")) {
??????????????????????? result.push($(this).attr("value"));
??????????????????? }
??????????????? });
??????????????? alert(result.join(","));
??????????? });
轉載于:https://www.cnblogs.com/suzh/archive/2011/03/25/1995195.html
總結
以上是生活随笔為你收集整理的jQuery CheckBox全选的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 找不到媳妇给愁的。。。
- 下一篇: Microsoft.Net框架程序设计学