<Scriptsrc= "Http://code.jquery.com/jquery-1.4.4.min.js"type= "Text/javascript"></Script> <Scripttype= "Text/javascript"> $(function() { $("#checkAll"). Click (function() { $('input[name= "Subbox"]'). attr ("checked", This. Checked); }); var$subBox= $("input[name= ' Subbox ']"); $subBox. Click (function(){ $("#checkAll"). attr ("checked", $subBox. Length== $("input[name= ' Subbox ']:checked"). Length? true : false); }); }); </Script> </Head><Body> <Div> <inputID= "Checkall"type= "checkbox" />Select All<inputname= "Subbox"type= "checkbox" />Item 1<inputname= "Subbox"type= "checkbox" />Item 2<inputname= "Subbox"type= "checkbox" />Item 3<inputname= "Subbox"type= "checkbox" />Item 4</Div></Body>
There's a problem with attr. Select all only use the first run once, click on the checkbox for all, you can select all, click once, or cancel all. However, after all, no matter what the click, it is useless ...
Baidu a bit with prop replace use attr can le
Difference http://www.cnblogs.com/zhwl/p/3520162.html
<Scriptsrc= "Http://code.jquery.com/jquery-1.4.4.min.js"type= "Text/javascript"></Script> <Scripttype= "Text/javascript"> $(function() { $("#checkAll"). Click (function() { $('input[name= "Subbox"]'). Prop ("checked", This. Checked); }); var$subBox= $("input[name= ' Subbox ']"); $subBox. Click (function(){ $("#checkAll"). Prop ("checked", $subBox. Length== $("input[name= ' Subbox ']:checked"). Length? true : false); }); }); </Script> </Head><Body> <Div> <inputID= "Checkall"type= "checkbox" />Select All<inputname= "Subbox"type= "checkbox" />Item 1<inputname= "Subbox"type= "checkbox" />Item 2<inputname= "Subbox"type= "checkbox" />Item 3<inputname= "Subbox"type= "checkbox" />Item 4</Div></Body>
Jqurey Select All and select All