JQuery checkbox full selection, total optional Implementation code summary _jquery

Source: Internet
Author: User
directly on the code.
<textarea id="runcode89892"><! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> <ptml xmlns=" http://www.w3.org/1999/xhtml "> <pead runat=" Server "> <title>index</title > <script src= "http://img.jb51.net/jslib/jquery/jquery14.js" ></script> <script type= "text/" JavaScript "> $ (Function () {$ (" #CheckAll "). Click (function () {var flag = $ (this). attr (" checked "); $ ("[Name=subbox]:checkbox"). each (function () {$ (this). attr ("checked", flag); })}) </script> </pead> <body> <div> <input id= "Checkall" type= "checkbox"/> Select all &L T;input name= "Subbox" type= "checkbox"/>1 <input "name= subbox" type= "checkbox"/>2 <input "name=" type = "checkbox"/>3 <input name= "Subbox" type= "checkbox"/>4 </div> </body> </ptml></textarea>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

The following code is more complete, is based on the control principle of JS implementation
Copy Code code as follows:

<script src= "Http://img.jb51.net/jslib/jquery/jquery14.js" ></script>
<script type= "Text/javascript" >
Select All
function Checkedall () {
$ (': CheckBox '). attr (' checked ', ' checked ');
}

No choice.
function Checkedno () {
$ (': CheckBox '). attr (' checked ', ');
}

Anti-election
function Checkedrev () {
var arr = $ (': CheckBox ');
for (Var i=0;i<arr.length;i++) {
arr[i].checked =! arr[i].checked;
}
}
</script>
<body>
<div>
<input id= "Checkall" type= "checkbox"/>
<input name= "Subbox" type= "checkbox"/>
<input name= "Subbox" type= "checkbox"/>
<input name= "Subbox" type= "checkbox"/>
<input name= "Subbox" type= "checkbox"/>
</div>
<input type= "button" Name= "Btncheckedall" value= "All selected" onclick= "Javascript:checkedall ();"/>
<input type= "button" Name= "Btncheckedno" value= "all do not choose" onclick= "Javascript:checkedno ();"/>
<input type= "button" Name= "Btncheckedrev" value= "onclick=" Javascript:checkedrev (); "/>
</body>


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.