jQuery 複選框全選/取消全選/反選

來源:互聯網
上載者:User

標籤:style   class   blog   code   java   http   

jQuery實現的複選框全選/取消全選/反選及獲得選擇的值。

完整代碼:

<!DOCTYPE html> <html> <head> <script type="text/javascript" src="../js/jquery-1.9.1.js"></script> <script type="text/javascript"> $(document).ready(function() { // 全選/取消全部 $("#checkAllChange").click(function() { if (this.checked == true) { $(".userid").each(function() { this.checked = true; }); } else { $(".userid").each(function() { this.checked = false; }); } // www.jbxue.com}); // 全選 $("#checkAll").click(function() { $(".userid").each(function() { this.checked = true; }); }); // 取消全部 $("#removeAll").click(function() { $(".userid").each(function() { this.checked = false; }); }); // 反選 $("#reverse").click(function() { $(".userid").each(function() { if (this.checked == true) { this.checked = false; } else { this.checked = true; } }) }); //大量刪除 $("#delAll").click(function() { var arrUserid = new Array(); $(".userid").each(function(i) { if (this.checked == true) { arrUserid[i] = $(this).val(); } }); alert("大量刪除的:" + arrUserid); }); }); </script> </head><body> <table border="1"> <tr> <td><input type="checkbox" id="checkAllChange" /></td> <td>使用者id</td> <td>使用者名稱</td> <td>電話</td> <td>地址</td> </tr> <tr> <td><input type="checkbox" class="userid" value="1" /></td> <td>1</td> <td>wangzs1</td> <td>18888000</td> <td>浦東</td> </tr> <tr> <td><input type="checkbox" class="userid" value="2" /></td> <td>2</td> <td>wangzs2</td> <td>18888001</td> <td>上海</td> </tr> <tr> <td><input type="checkbox" class="userid" value="3" /></td> <td>3</td> <td>wangzs3</td> <td>18888002</td> <td>河南</td> </tr> <tr> <td><input type="checkbox" class="userid" value="4" /></td> <td>4</td> <td>wangzs4</td> <td>18888003</td> <td>許昌</td> </tr> <tr> <td></td> <td><input type="button" id="checkAll" value="全選" /></td> <td><input type="button" id="removeAll" value="取消全部" /></td> <td><input type="button" id="reverse" value="反選" /></td> </tr> <tr> <td colspan="4" align="center"><input type="button" value="大量刪除" id="delAll"></td> </tr> </table> </body></html>

聯繫我們

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