JS获取radio和checkbox一系列html元素

来源:互联网 发布:域名 服务器 编辑:程序博客网 时间:2024/06/04 18:33

 

<script type="text/javascript">
function openChildWindow()
{

var Str='aaa,bbb,ccc,ddd,';
alert(Str);
var stringArray=Str.split(',');
for(var i=0;i<stringArray.length-1;i++)
{
alert(stringArray[i]);
}
alert("asdfa");
window.open('searchuser','','toolbar,menubar,scrollbars,resizable,status,location,directories,copyhistory,height=600,width=400');

<!--window.ShowModelDialog("child.jsp");-->
}
function update(value)
{

alert();
document.getElementById("childvalue").innerHTML=value;
}
function test()
{
alert("test");
var checkbox=document.getElementsByName('test');
var radio=document.getElementsByName('test1');
for(var i=0;i<checkbox.length;i++)
{
if(checkbox[i].checked)
alert(checkbox[i].value);


}
for(var j=0;j<radio.length;j++)
{
if(radio[j].checked)
{
alert(radio[j].value);
}

}

}
</script>
</head>

<body onload="test();">
   <a href="searchuser">查询</a>
   <input type="button" onclick="openChildWindow();" value="打开子窗口" />

   <span id="childvalue"> </span>
   <form action="">
    <table>
     <tr>
      <td><input type="checkbox" value="1" checked="checked" name="test"/></td>
      <td><input type="checkbox" value="2" name="test"/></td>
      <td><input type="checkbox" value="3" checked="checked" name="test"/></td>
      <td><input type="checkbox" value="4" checked="checked" name="test"/></td>
      <td><input type="radio" value="5" name="test1"/></td>
      <td><input type="radio" value="6" name="test1"/></td>
      <td><input type="radio" value="7" checked="checked" name="test1"/></td>
      <td><input type="radio" value="8" name="test1"/></td>
     </tr>
    </table>

   </form>

</body>
</html>

原创粉丝点击