JQ_表格的选取全选反选

<!DOCTYPE html>
<html lange="en">      <!-- 设置语音 -->
<head>
 <meta charset="UFT-8"> <!-- 设置编码格式 -->
 <title>Title</title>
 

</head>
<body>
  <input type="button" value="全选"  οnclick="choseAll()"/>
  <input type="button" value="反选" οnclick="revserAll()"/>
  <input type="button" value="取消" οnclick="cancleAll()"/>
  <table border="1">
   <thead>
    <tr>
     <th>选项</th>
     <th>IP</th>
     <th>PORT</th>
    </tr>
   </thead>
   <tbody id="td">
    <tr>
     <td><input type="checkbox" /></td>
     <td>192.168.0.1</td>
     <td>80</td>
    </tr>
    <tr>
     <td><input type="checkbox"/></td>
     <td>192.168.0.2</td>
     <td>82</td>
    </tr>
    <tr>
     <td><input type="checkbox"/></td>
     <td>192.168.0.3</td>
     <td>83</td>
    </tr>
   </tbody>
   
  </table>
  <script src="jquery-1.12.4.js"></script>   <!-- 引入jq模块 -->
  <script>
   function choseAll(){
    console.log("choseall");
    /*$("#td :checkbox") 选择标签*/
    $("#td :checkbox").prop('checked',true);   
   }
   function cancleAll(){
    $('#td :checkbox').prop('checked',false);
   }
   
   function revserAll1(){
    /*each() JQ中的循环 在其中添加函数*/
    /*prop() 函数一个参数表示获取这个属性的值 两个参数设置这个属性的值*/
    $('#td :checkbox').each(function (){
      console.log("revserAll");
      if(this.checked){
       this.checked = false;
      }else{
       this.checked = true;
      }
     })
   }
   
   /*
   document.getElementById('td'); --> <tbody id="td">...</tbody>
   $('#td'); -->[tbody#td, context: document, selector: "#td"]
   */
   /*$(this) 将Dom对象转换成JQ的对象*/
   function revserAll2(){
    $('#td :checkbox').each(function (){
     console.log("revserAll");
     
     if($(this).prop('checked')){
      $(this).prop('checked',false);
     }else{
      $(this).prop('checked',true);
     }
    })
   }
   
   function revserAll(){
    $('#td :checkbox').each(function (){
/*三目运算符 :
条件?结果1:结果2
*/
     var v = $(this).prop('checked')?false:true;
     $(this).prop('checked',v);
    })
   }
  </script>
  
</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值