javaScript選框的全選與取消

<div> <input type="button" value="全選" onclick="quan()"> <input type="button" value="取消" onclick="cancel()"> <input type="button" value="反選" onclick="reverse()"> <table> <thead> <tr> <th>選擇</th> <th>主機名</th> <th>端口</th> </tr> </thead>code

<tbody id="tb">
          <tr>
              <td><input type="checkbox"></td>
               <td>1.1.1.1</td>
               <td>11</td>
          </tr>
          <tr>
              <td><input type="checkbox"></td>
               <td>1.1.1.2</td>
               <td>11</td>
          </tr>
        <tr>
               <td><input type="checkbox"></td>
               <td>1.1.1.3</td>
               <td>11</td>
          </tr>
      </tbody>
  </table>

</div>get

function quan() { var tb=document.getElementById('tb') var tb_list=tb.children for(var i=0;i<tb_list.length;i++){ var current=tb_list[i] var checkbox= current.children[0].children[0] checkbox.checked=true } } function cancel() { var tb=document.getElementById('tb') var tb_list=tb.children for(var i=0;i<tb_list.length;i++){ var current=tb_list[i] var checkbox= current.children[0].children[0] checkbox.checked=false } }input

function reverse() {
        var tb=document.getElementById('tb')
       var tb_list=tb.children
      for(var i=0;i<tb_list.length;i++){
           var current=tb_list[i]
         var checkbox= current.children[0].children[0]
         if(checkbox.checked==true){
               checkbox.checked=false
         }else{
               checkbox.checked=true
         }
      }
  }
相關文章
相關標籤/搜索