全选,取消全选gridview中的checkbox, 点击某一项的checkbox时,自动识别是否应该将checkAll设为选中还是非选中...

全选,取消全选gridview中的checkbox, 点击某一项的checkbox时,自动识别是否应该将checkAll设为选中还是非选中

 

可以尝试将checkbox直接用html控件,此处用了runnat="server" , 如果用html控件不能执行到相应的脚本,提示脚本函数未定义,请加上runat="server"为checkbox

 

<div class="mainContent">
<asp:GridView ID="gvContent" runat="server" DataKeyNames="ContentID" AutoGenerateColumns="False" PageSize="20" AllowPaging="True">
  <Columns>
    <asp:TemplateField>
      <HeaderTemplate>
        <input type="checkbox" id="checkAll" name="checkAll" runat="server" οnclick="checkAll();" />
      </HeaderTemplate>
      <ItemTemplate>
        <input type="checkbox" id="checkItem" name="checkItem" runat="server" οnclick="checkItem();" />
      </ItemTemplate>
     </asp:TemplateField>
  </Columns>
</asp:GridView>

 

 

 

var checkAll = function () {
  if ($("input[id$='checkAll']").prop("checked") == true) {
    $(":checkbox:input[name$='checkItem']").prop("checked", true);
  }
  else {
    $(":checkbox:input[name$='checkItem']").prop("checked", false); 
  }
}

var checkItem = function (obj) {  
  var count = $(":checkbox:input[name$='checkItem']").length;
  var checkedCount = $(":checkbox:input[name$='checkItem']:checked").length;
  var checkAllchecked = $("[id$='checkAll']").prop("checked");
  if (count == checkedCount) {
    if (!checkAllchecked) {
      $("[id$='checkAll']").prop("checked", true)
    }
  }
  else {
    if (checkAllchecked) {
      $("[id$='checkAll']").prop("checked", false)
    }
  }
}

转载于:https://www.cnblogs.com/vihone/archive/2013/06/02/3114176.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值