jquery table下的複選框選中、取消

來源:互聯網
上載者:User

標籤:function   jquery   

<!doctype html><html><head><meta charset="utf-8"><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>首頁</title><!-- 新 Bootstrap 核心 CSS 檔案 --><link rel="stylesheet" href="../../../css/bootstrap.min.css"><!-- jQuery檔案。務必在bootstrap.min.js 之前引入 --><script src="../../../js/jquery.min.js"></script><!-- 最新的 Bootstrap 核心 JavaScript 檔案 --><script src="../../../js/bootstrap.min.js"></script><script language="javascript">$().ready(function() {    $("input[id=all]").click(function(){        var allchecked = this.checked;        var arr = $(this).parent().parent().parent().find("input");        for(var i = 1;i<arr.length;i++){            arr[i].checked = allchecked;        }    });        $("input[id=inlineCheckbox1]").click(function(){        var arr = $(this).parent().parent().parent().find("input");        for(var i = 1;i<arr.length;i++){            if(arr[i].checked){                arr[0].checked = true;                    return;            }        }                var arr2 = $(this).parent().parent().parent().find("input[checked=true]");        if(arr2.length ==0){        arr[0].checked = false;            }                })        });</script></head><body>  <table  class="table">      <tr>        <th>一級菜單</th>        <th>二級菜單</th>    </tr>    <tr><td><label class="checkbox-inline">  <input type="checkbox"  id="all" value="option1"> 系統管理</label></td>        <td>        <label class="checkbox-inline">          <input type="checkbox" id="inlineCheckbox1"  value="option1"> 使用者管理        </label>             <label class="checkbox-inline">          <input type="checkbox" id="inlineCheckbox1" value="option1"> 使用者管理        </label>     <label class="checkbox-inline">          <input type="checkbox" id="inlineCheckbox1" value="option1"> 使用者管理        </label>     <label class="checkbox-inline">          <input type="checkbox" id="inlineCheckbox1" value="option1"> 使用者管理        </label>        </td>    </tr>   <tr><td><label class="checkbox-inline">  <input type="checkbox" id="all" value="option1"> 系統管理</label></td>        <td>        <label class="checkbox-inline">          <input type="checkbox" id="inlineCheckbox1" value="option1"> 使用者管理        </label>             <label class="checkbox-inline">          <input type="checkbox" id="inlineCheckbox1" value="option1"> 使用者管理        </label>     <label class="checkbox-inline">          <input type="checkbox" id="inlineCheckbox1" value="option1"> 使用者管理        </label>     <label class="checkbox-inline">          <input type="checkbox" id="inlineCheckbox1" value="option1"> 使用者管理        </label>        </td>    </tr>  </table></body></html>


本文出自 “老牛Java” 部落格,請務必保留此出處http://liuyj.blog.51cto.com/2340749/1577685

jquery table下的複選框選中、取消

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.