作家
登录

基于JQuery实现CheckBox全选全不选

作者: 来源:www.28hudong.com 2013-03-30 00:50:42 阅读 我要评论

所以我就参照网上的例子试着自己写了一个,达到了自己想要的效果,其实这也是一个很简单的例子,其中有不足的地方还望大家能够给予指出。下面把代码贴出来给大家看看 复制代码 代码如下: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="checkAll.aspx.cs" Inherits="checkAll" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script src="Js/jquery-1.5.2.js" type="text/javascript"></script> <script src="Js/jquery-1.5.2.min.js" type="text/javascript"></script> <script language="javascript" type="text/javascript"> $(document).ready(function () { //全选或全不选 $("#chkAll").click(function () {//当点击全选框时 var flag = $("#chkAll").attr("checked");//判断全选按钮的状态 $("[id$='Item']").each(function () {//查找每一个Id以Item结尾的checkbox $(this).attr("checked", flag);//选中或者取消选中 }); }); //如果全部选中勾上全选框,全部选中状态时取消了其中一个则取消全选框的选中状态 $("[id$='Item']").each(function () { $(this).click(function () { if ($("[id$='Item']:checked").length == $("[id$='Item']").length) { $("#chkAll").attr("checked", "checked"); } else $("#chkAll").removeAttr("checked"); }); }); }); </script> </head> <body> <form id="form1" runat="server"> <div> <table> <tr> <td width="100px"> <asp:CheckBox ID="chkAll" runat="server" Text="全选"/> </td> </tr> <tr> <td width="100px"> <asp:CheckBox ID="chk1_Item" runat="server"/> </td> </tr> <tr> <td width="100px"> <asp:CheckBox ID="chk2_Item" runat="server"/> </td> </tr> <tr> <td width="100px"> <asp:CheckBox ID="chk3_Item" runat="server"/> </td> </tr> <tr> <td width="100px"> <asp:CheckBox ID="chk4_Item" runat="server"/> </td> </tr> <tr> <td width="100px"> <asp:CheckBox ID="chk5_Item" runat="server"/> </td> </tr> <tr> <td width="100px"> <asp:CheckBox ID="chk6_Item" runat="server"/> </td> </tr> <tr> <td width="100px"> <asp:CheckBox ID="chk7_Item" runat="server"/> </td> </tr> </table> </div> </form> </body> </html>

  推荐阅读

  jquery中获取select选中值的代码

jquery获取select选择的文本与值 获取select 选中的 text : $("#ddlregtype").find("option:selected").text(); 获取select选中的 value: $("#ddlregtype ").val(); 获取select选中的索引: $("#ddlregtype ").get(>>>详细阅读


本文标题:基于JQuery实现CheckBox全选全不选

地址:http://www.17bianji.com/kaifa2/JS/24484.html

关键词: 探索发现

乐购科技部分新闻及文章转载自互联网,供读者交流和学习,若有涉及作者版权等问题请及时与我们联系,以便更正、删除或按规定办理。感谢所有提供资讯的网站,欢迎各类媒体与乐购科技进行文章共享合作。

网友点评
自媒体专栏

评论

热度

精彩导读
栏目ID=71的表不存在(操作类型=0)