<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <form action="" name="form1"> <table> <tr> <td><input type="checkbox" value=""></td> <td>主题</td> <td>发布人</td> <td>发布时间</td> </tr> <tr> <td><input type="checkbox" value=""></td> <td>清明节</td> <td>张三</td> <td>2018</td> </tr> <tr> <td><input type="checkbox" value=""></td> <td>愚人节</td> <td>李四</td> <td>2016</td> </tr> <tr> <td><input type="checkbox" value=""></td> <td>儿童节</td> <td>小明</td> <td>2019</td> </tr> <tr> <td><input type="checkbox" value=""></td> <td>植树节</td> <td>小红</td> <td>2017</td> </tr> <tr> <td><input type="button" name="button" class="buttoncss" onclick="checkall(form1,status)" value="全选"></td> <td><input type="button" name="button" class="buttoncss" onclick="switchall(form1,status)" value="反选"></td> <td><input type="button" name="button" class="buttoncss" onclick="uncheckall(form1,status)" value="不选"></td> </tr> </table> </form> </body> <script> function checkall(form1,status){ var elements=form1.getElementsByTagName('input'); for(var i=0;i<elements.length;i++){ if(elements[i].type=='checkbox'){ if(elements[i].checked==false){ elements[i].checked=true; } } } } function switchall(form1,status){ var elements = form1.getElementsByTagName('input'); for(var i=0; i<elements.length; i++){ if(elements[i].type == 'checkbox'){ if(elements[i].checked==true){ elements[i].checked=false; }else if(elements[i].checked==false){ elements[i].checked=true; } } } } function uncheckall(form1,status){ var elements=form1.getElementsByTagName('input'); for(var i=0;i<elements.length;i++){ if(elements[i].type=='checkbox'){ if(elements[i].checked==true){ elements[i].checked=false; } } } } </script> </html>
这里实现的是表单复选框的小功能,清明时节雨纷纷,清明那几天没有下,今天下雨了,天气下降了几度,有点凉。