点击表格中任意处都可以选中多选框

<!DOCTYPE html>
<html>
<head>
  <mata charset="utf-8">
  <style>
    .bgRed{background-color:#fff}
  </style>
</head> 
<body>
     <div class="administration-body clearfix">
        <table border="1px solid #aaa" width="100%" style="table-layout:fixed;" id="tableModel" >
         <!-- 表头 -->
             <tr>
                <td width="10%"><input class="use" type="checkbox" name="use"></td>
                <td width="5%">姓氏</td>
                <td width="10%">手机号</td> 
                <td width="7%">评价来源</td>
                <td width="5%">评价打分</td>
                <td width="18%">评价详情</td>
                <td width="15%">评价时间</td>
                <td width="17%">#^^</td>
                <td width="19%">c</td>
                <td width="7%">操作</td>
             </tr>
             <tr>
                <td width="10%"><input class="use" type="checkbox" name="use"></td>
                <td width="5%">姓氏</td>
                <td width="10%">手机号</td> 
                <td width="7%">评价来源</td>
                <td width="5%">评价打分</td>
                <td width="18%">评价详情</td>
                <td width="15%">评价时间</td>
                <td width="5%">是否跟进</td>
                <td width="19%">跟进情况备注</td>
                <td width="7%">操作</td>
             </tr>
      </table>
    </div>
 <script src="jquery-1.8.3.min.js"></script> 
  <script src="../jquery/jquery-1.8.3.min.js"></script> 
<script>
  //透传事件(点击选框时就选中了,但是在选框外面是个tr,同时又触发tr点击事件,当执行tr,click时判断check是否未选中时这时,check是选中状态,就有把checkbox,取消了)
  /*$("tr").toggle(function(){
    $(this).children().eq(0).children("input").prop('checked',true);
  },function(){
      $(this).children().eq(0).children("input").prop("checked",false);
  });*/




  //解决方案一:添加一个属性
   /*$("tr").click(function () {
     $(this).toggleClass("bgRed");
      if ($(this).css("background-color") != $(document.body).css("background-color")) {
           $(this).children().eq(0).children("input").attr("checked", true);
      } else {
           $(this).children().eq(0).children("input").attr("checked", false);
      }
  });*/


//解决方案二:
  var a=false;
  $(".use").click(function(){
    a=true;
   })
  $("tr").click(function(){
    if(a){
      a=false;
    }else{
      if($(this).children().eq(0).children("input").is(':checked')){
        $(this).children().eq(0).children("input").prop("checked",false);
      }else{
        $(this).children().eq(0).children("input").prop('checked',true);
      }
    }
 });


</script>
</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值