Jscript複選框

來源:互聯網
上載者:User

標籤:des   style   blog   http   color   java   io   for   ar   

<!doctype html><html lang="en"> <head>  <meta charset="UTF-8">  <meta name="Generator" content="EditPlus®">  <meta name="Author" content="">  <meta name="Keywords" content="">  <meta name="Description" content="">  <title>Document</title>    <script type="text/javascript">    <!--全選框的方法-->        function check(object){                                var  checks=document.getElementsByName("checks");            if (checks!=null)            {                for (var i=0;i<checks.length;i++ )                {                    checks[i].checked=document.getElementById("checkAll").checked;                }            }        };        <!--這裡要注意如果 var checkall=document.getElementById("checkAll").checked; 下面判斷 checkall==true 語句是錯的!邏輯是對的,文法是錯的-->        function checks(){            var checkall=document.getElementById("checkAll");            var checks=document.getElementsByName("checks");            var count=0;            var sum=0;            for (var i=0;i<checks.length ;i++ )            {                if (checks[i].checked==true)                {                    count=count+1;                }                if(checks[i].checked==false){                    sum=sum+1;                }            }            alert(sum);            if (count==checks.length)            {                checkall.checked=true;            }            if (sum>0)            {                if (checkall.checked==true)                {                    checkall.checked=false;                }            }        }    </script> </head> <body>        <div id="" class="">        <table>        <tr>            <td><input type="checkbox" id="checkAll" onclick="check(this)"></td>            <td>商品名稱</td>            <td>商品價格</td>            <td>商品描述</td>        </tr>        <tr>            <td><input type="checkbox" name="checks" onclick="checks()"></td>            <td>酒精</td>            <td>12</td>            <td>酒精你懂的</td>        </tr>        <tr>                    <td><input type="checkbox" name="checks" onclick="checks()"></td>            <td>飯盒</td>            <td>15</td>            <td>吃飯的工具,你不知道?</td>        </tr>        <tr>            <td><input type="checkbox" name="checks" onclick="checks()"></td>            <td>酒精</td>            <td>12</td>            <td>酒精你懂的</td>        </tr>        <tr>                    <td><input type="checkbox" name="checks" onclick="checks()"></td>            <td>飯盒</td>            <td>15</td>            <td>吃飯的工具,你不知道?</td>        </tr>        <tr>            <td><input type="checkbox" name="checks" onclick="checks()"></td>            <td>酒精</td>            <td>12</td>            <td>酒精你懂的</td>        </tr>        <tr>                    <td><input type="checkbox" name="checks" onclick="checks()"></td>            <td>飯盒</td>            <td>15</td>            <td>吃飯的工具,你不知道?</td>        </tr>        </table>    </div> </body></html>

運行

 

 

Jscript複選框

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.