标签:javascript
示例代码:全选、全不选、反选
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html;charset=utf-8"> <title>Javascript测试</title> <script type="text/javascript"> onload=function(){ document.getElementById(‘btnSelectAll‘).onclick=function(){ var inputObjs = document.getElementsByTagName("input"); for(var i=0;i<inputObjs.length;i++) { if(inputObjs[i].type=="checkbox") { inputObjs[i].checked = true; } } }; document.getElementById(‘btnSelectNone‘).onclick=function(){ var inputObjs = document.getElementsByTagName("input"); for(var i=0;i<inputObjs.length;i++) { if(inputObjs[i].type=="checkbox") { inputObjs[i].checked = false; } } }; document.getElementById(‘btnSelectReverse‘).onclick=function(){ var inputObjs = document.getElementsByTagName("input"); for(var i=0;i<inputObjs.length;i++) { if(inputObjs[i].type=="checkbox") { inputObjs[i].checked = !inputObjs[i].checked; } } }; }; </script> </head> <body> <input type="button" id="btnSelectAll" value="全选"/> <input type="button" id="btnSelectNone" value="全不选"/> <input type="button" id="btnSelectReverse" value="反选"/> <input type="checkbox" value="1"/>吃饭 <input type="checkbox" value="2"/>睡觉 <input type="checkbox" value="3"/>跑步 <input type="checkbox" value="4"/>读书 <input type="checkbox" value="5"/>看电影 </body> </html>
效果图
标签:javascript
原文地址:http://lsieun.blog.51cto.com/9210464/1844868