1 <!DOCTYPE HTML>2 <HTML>3 <Head>4 <MetaCharSet= "UTF-8">5 <Scriptsrc=".. /js/jquery1.8.3.min.js "></Script> 6 <title>Form Action-checkbox</title>7 <style>8 *{margin:10px}9 </style>Ten </Head> One <Body> A <formMethod= "POST"Action=""> - What's your favorite sport? - <BR/> the <inputtype= "checkbox"name= "Items"value= "Football"ID= "ZQ"/><label for= "ZQ">Football</label> - <inputtype= "checkbox"name= "Items"value= "Basketball"ID= "LQ"/><label for= "LQ">Basketball</label> - <inputtype= "checkbox"name= "Items"value= "Badminton"ID= "Ymq"/><label for= "Ymq">Badminton</label>Badminton - <inputtype= "checkbox"name= "Items"value= "Table tennis"ID= "PPQ"/><label for= "PPQ">Table tennis</label> + <BR/> - <inputtype= "button"ID= "Checkedall"value= "Select All"/> + <inputtype= "button"ID= "Checkedno"value= "All is not selected"/> A <inputtype= "button"ID= "Checkedrev"value= "Reverse Selection"/> at - <inputtype= "button"ID= "Send"value= "Submit"/> - </form> - <Script> - $(function(){ - //Select All in $("#CheckedAll"). Click (function(){ - $("Input[name=items]"). attr ("checked",true); to }); + //all do not choose - $("#CheckedNo"). Click (function(){ the $("Input[name=items]"). attr ("checked",false); * }); $ Panax Notoginseng //Inverse Selection - $("#CheckedRev"). Click (function(){ the //checkbox + varCheckelem= $("Input[name=items]"); A /** Method One: the For (var i = 0; i<checkelem.length;i++) { + checkelem[i].checked =!checkelem[i].checked; - } $ **/ $ //Method Two: - Checkelem.each (function(){ - This. Checked= ! This. Checked; the }); - /** Method Three:Wuyi Checkelem.each (function () { the if ($ (this). attr ("checked")) { - $ (this). attr ("checked", false); Wu }else{ - $ (this). attr ("Checked", true); About } $ }); - **/ - }); - }) A </Script> + </Body> the </HTML>
Full selection, no selection, and inverse selection of jquery