本帖最后由 曾林魁 于 2013-9-15 18:41 编辑
为什么代码这样写点击全不选按钮达不到效果没用- <!DOCTYPE html>
- <html>
- <head>
- <title>MyHtml.html</title>
- <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
- <meta http-equiv="description" content="this is my page">
- <meta http-equiv="content-type" content="text/html; charset=gb312">
- <!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
- <style type=text/css>
- td{
- border:1px;
- border-style:solid;
- border-color:#000000;
- }
- </style>
- </head>
- <body>
- <form action="1.html" id="form1">
- <table>
- <tr>
- <td><input type='text' value='zenglinkui'/></td>
- <td><input type='button' value='确认'/></td>
- </tr>
- <tr>
- <td>爱好:</td>
- <td><input type="checkbox" name="preference" value="sing" />唱歌
- <input type="checkbox" name="preference" value="dance" />跳舞
- <input type="checkbox" name="preference" value="read" />读书
- </td>
- </tr>
- <tr>
- <td colspan='2'>
- <input type='button' value='全选' onclick="allCheck()"/>
- <input type='button' value='全不选' onclick="allUnCheck()"/>
- </td>
- </tr>
- </table>
- </form>
- </body>
- <script type="text/javascript">
- //window.onload = function(){ //}
- function allCheck(){
- var inputElement = document.getElementsByName("preference");
- for(i=0;i<inputElement.length;i++){
- inputElement[i].setAttribute("checked","checked");
- }
- }
- function allUnCheck(){
- var inputElement1 = document.getElementsByName("preference");
- for(i=0;i<inputElement1.length;i++){
- alert(inputElement1.length);
- //alert("sdfjl");
- if (inputElement[i].checked) {
- inputElement1[i].checked = null;
- //inputElement1[i].removeAttribute('checked');
- }
- // }else{
- // inputElement[i].setAttribute("checked","checked");
- // }
- }
- }
- </script>
- </html>
复制代码 |