js實現復選框全選和不選
阿新 • • 發佈:2018-10-11
onclick check checkbox rip () nbsp title false style
<html> <head> <title></title> </head> <style> </style> <script> window.onload =function(){ var oDiv=document.getElementById(‘div1‘) //獲取到那個div var oInput=oDiv.getElementsByTagName(‘input‘) //獲取到div下面的所有input document.getElementById(‘chooseAll‘).onclick=function(){ for(var i=0;i<oInput.length;i++){ oInput[i].checked=true } } document.getElementById(‘noChoose‘).onclick=function(){ for(var i=0;i<oInput.length;i++){ oInput[i].checked=false } } } </script> <body> <input id="chooseAll" type="button" value="全選" /> <input id="noChoose" type="button" value="不選"/> <div id="div1"> <input type="checkBox" /> <input type="checkBox" /> <input type="checkBox" /> <input type="checkBox" /> <input type="checkBox" /> <input type="checkBox" /> <input type="checkBox" /> <input type="checkBox" /> <input type="checkBox" /> </div> </body> </html>
js實現復選框全選和不選