js 能取到所有相同ID的值吗
<form name= "form1 ">
<input id= "1 " name= "ch1 " type= "checkbox " value=1>
<input id= "1 " name= "ch2 " type= "checkbox " value=2>
<input id= "1 " name= "ch3 " type= "checkbox " value=3>
<input id= "2 " name= "ch1 " type= "checkbox " value=1>
<input id= "2 " name= "ch2 " type= "checkbox " value=2>
<input id= "2 " name= "ch3 " type= "checkbox " value=3>
<input type= "button " onClick= "check() ">
</form> 能通过ID获取六个的值吗??
------解决方案--------------------id理论上讲应该是唯一的,只是IE里混用
var objs=document.getElementsByTagName( "input ")
for(var i=0;i <objs.length;i++)
{
if((objs[i].text= "checkbox ")&&(/^ch/.test(objs[i].name)))
{
alert(objs[i].value)
}
}
------解决方案-------------------- <form name= "form1 ">
<input id= "1 " name= "ch1 " type= "checkbox " value=1>
<input id= "1 " name= "ch2 " type= "checkbox " value=2>
<input id= "1 " name= "ch3 " type= "checkbox " value=3>
<input id= "2 " name= "ch1 " type= "checkbox " value=1>
<input id= "2 " name= "ch2 " type= "checkbox " value=2>
<input id= "2 " name= "ch3 " type= "checkbox " value=3>
<input type= "button " onClick= "check() ">
</form>
<script language=javascript>
var objs=document.getElementsByTagName( "input ")
for(var i=0;i <objs.length;i++)
{
if((objs[i].text= "checkbox ")&&(/^ch/.test(objs[i].name)))
{
alert(objs[i].value)
}
}
</script>