zoukankan      html  css  js  c++  java
  • Jquery,全选,反选,

    <!DOCTYPE html>
    <html>
      <head>
        <meta charset="utf-8">
        <title></title>
        <script src="/vue/js/jquery-3.3.1.js" type="text/javascript">  </script>
        <script type="text/javascript">
        $(function ()
        {
           //所有复选选中让 全选的复选框选中
          $("table tr td input[type='checkbox']").click(function(){
              var check= $("table tr td input[type='checkbox']:checked").length;
              var all=$("table tr td input[type='checkbox']").length;
              if(check==all)
              {
                $("#all").prop("checked",true)
              }
              else {
                $("#all").prop("checked",false)
              }
          })
            $("#all").click(function(){
              var c=  $("#all").prop("checked")
              if (c==true) {
                $("table tr td input[type='checkbox']").prop("checked",true)
              }
              else {
                  $("table tr td input[type='checkbox']").prop("checked",false)
              }
            })
      //反选按钮
          $("#selectno").click(function(){
            //获取所有未选中行的checkbox长度
          var no=  $("table tr td input[type='checkbox']:not(:checked)").length
              //获取所有选中行的checkbox长度
          var yes= $("table tr td input[type='checkbox']:checked").length
                alert( '选中长度'+yes)
                alert('未选中长度'+no)
                $("table tr td input[type='checkbox']").each(function(){
                $(this).prop("checked",!$(this).prop("checked"))
                })
            })
        })
        </script>
      </head>
      <body>
        全选:<input type="checkbox" id="all" >
        <input type="button" id="selectno" value="反选" >
    <table>
      <tr>
        <td>状态</td>   <td>姓名</td>   <td>工资</td>
      </tr>
      <tr>
        <td> <input type="checkbox" name="" value=""> </td>
        <td>张三</td>
        <td>2000</td>
      </tr>
      <tr>
         <td> <input type="checkbox" name="" value=""> </td>
         <td>李四</td>
         <td>200</td>
      </tr>
      <tr>
         <td> <input type="checkbox" name="" value=""> </td>
         <td>王五</td>
         <td>200</td>
      </tr>
      <tr>
         <td> <input type="checkbox" name="" value=""> </td>
         <td>赵六</td>
         <td>200</td>
      </tr>
      <tr>
         <td> <input type="checkbox" name="" value=""> </td>
         <td>田七</td>
         <td>200</td>
      </tr>
      <tr>
         <td> <input type="checkbox" name="" value=""> </td>
         <td>王八</td>
         <td>200</td>
      </tr>
    
    </table>
    
      </body>
    </html>
  • 相关阅读:
    深入理解类的填充规则
    深入理解C++虚函数表
    Java接入图灵机器人,实现与机器人聊天
    flex弹性布局学习笔记
    gulp插件gulp-usemin简单使用
    js基础知识温习:Javascript中如何模拟私有方法
    一次体验很不爽的面试经历
    JavaScript中in操作符(for..in)、Object.keys()和Object.getOwnPropertyNames()的区别
    js基础知识温习:构造函数与原型
    js基础知识温习:js中的对象
  • 原文地址:https://www.cnblogs.com/tianranhui/p/9813729.html
Copyright © 2011-2022 走看看