(14)JS实现全选功能

来源:互联网 发布:精雕软件下载 编辑:程序博客网 时间:2024/06/05 02:31

思路:

在实现全选功能的时候,只需要选定某个div内的所有checkbox,将其check属性值设置为true即可。代码如下:

<!DOCTYPE HTML><!----><html><head><meta charset="utf-8"><title></title> <script>window.onload=function(){var oBtn=document.getElementById('btn1');var oDiv=document.getElementById('div1');var aCh=oDiv.getElementsByTagName('input');oBtn.onclick=function(){for(var i=0;i<aCh.length;i++){aCh[i].checked=true;}};};</script></head><body><input id="btn1" type="button" value="全选"/><div id="div1"><input type="checkbox"/><br><input type="checkbox"/><br><input type="checkbox"/><br><input type="checkbox"/><br><input type="checkbox"/><br><input type="checkbox"/><br><input type="checkbox"/><br><input type="checkbox"/><br><input type="checkbox"/><br><input type="checkbox"/><br><input type="checkbox"/><br><input type="checkbox"/><br><input type="checkbox"/><br><input type="checkbox"/><br><input type="checkbox"/><br></div></body></html>
效果图:



0 0
原创粉丝点击