首页 > 代码库 > js表单操作

js表单操作

<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>全选</title></head><body>    <input id="a" type="checkbox" /><label for="a">反选</label>    <input id="b" type="checkbox" /><label for="b">全选</label><div id="area">    <input type="checkbox" />    <input type="checkbox" />    <input type="checkbox" checked=true />    <input type="checkbox" checked=true />    <input type="checkbox" checked=true />    <input type="checkbox" checked=true />    <input type="checkbox" />    <input type="checkbox" />    <input type="checkbox" />    <input type="checkbox" /></div></body></html><script type="text/javascript">var oInput=document.getElementById("a");var bInput=document.getElementById("b");var aInput=document.getElementsByTagName("div")[0].getElementsByTagName("input");bInput.onclick=function(){    if(this.checked){        for (var i = 0; i < aInput.length; i++){                aInput[i].checked=true;            }    }else{        for (var i = 0; i < aInput.length; i++){                aInput[i].checked=false;            }    }}oInput.onclick=function(){    for (var i = 0; i < aInput.length; i++){        if(aInput[i].checked){            aInput[i].checked=false;        }else{            aInput[i].checked=true;        }            };}</script>

 

js表单操作