标签:
| <!doctype html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="Generator" content="EditPlus®"> | |
| <meta name="Author" content=""> | |
| <meta name="Keywords" content=""> | |
| <meta name="Description" content=""> | |
| <title>Document</title> | |
| <script> | |
| function checkAll( booleanValue ) | |
| { | |
| var checkboxset= document.getElementsByName("hobby"); | |
| for(var i =0;i<checkboxset.length; i++ ) | |
| { | |
| checkboxset[i].checked = booleanValue; | |
| } | |
| } | |
| function reverseCheck(){ | |
| //找到所有的checkbox | |
| //针对每一个checkbox,判断其当前的checked属性,并且置反 | |
| var checkboxset= document.getElementsByName("hobby"); | |
| for(var i =0;i<checkboxset.length; i++ ) | |
| { | |
| checkboxset[i].checked = !checkboxset[i].checked; | |
| } | |
| } | |
| </script> | |
| </head> | |
| <body> | |
| <h1>请选择你的爱好:</h1> | |
| 全选/全不选<input type="checkbox" name="hobbys" onclick="checkAll(this.checked)" /><br/> | |
| <input type="checkbox" name="hobby" value="football" onclick=""/>足球 | |
| <input type="checkbox" name="hobby" value="basketball" onclick=""/>篮球 | |
| <input type="checkbox" name="hobby" value="swim" onclick=""/>游泳 | |
| <input type="checkbox" name="hobby" value="singing" onclick=""/>唱歌<br/> | |
| <input type="button" value="全选" onclick="checkAll(true)"/> <input type="button" value="全不选" onclick="checkAll(false)"/> | |
| <input type="button" value="反选" onclick="reverseCheck()"/> | |
| </body> | |
| </body> | |
| </html> | |
JavaScript下全选反选的Demo程序里实现checkmeonly函数 DOM
标签:
原文地址:http://www.cnblogs.com/FG123/p/4445373.html