单选框问题(我点按钮一让页面上所有单选按钮值为1的选中,点按钮二让所有单选按钮为2的选中
单选框问题(我点按钮一让页面上所有单选按钮值为1的选中,点按钮二让所有单选按钮为2的选中,请问如何实现
------解决方案--------------------example:
<input type= "radio " name= "r1 " value= "1 ">
<input type= "radio " name= "r2 " value= "1 ">
<input type= "radio " name= "r3 " value= "1 ">
<input type= "radio " name= "r11 " value= "2 ">
<input type= "radio " name= "r22 " value= "2 ">
<input type= "radio " name= "r33 " value= "2 ">
<input type= "button " value= "选择1 " onclick= "selectRadio(1) "/>
<input type= "button " value= "选择2 " onclick= "selectRadio(2) "/>
<script language= "JavaScript ">
<!--
function selectRadio(v)
{
var ipt=document.getElementsByTagName( "INPUT ");
for(i=0;i <ipt.length;i++)
{
if(ipt[i].type== "radio ")
{
ipt[i].checked=(ipt[i].value==v);
}
}
}
//-->
</script>
------解决方案-------------------- <script>
function _check(intValue){
var radioObj = document.getElementsByTagName( "input ");
for (i=0;i <radioObj.length;i++){
if (radioObj[i].type == "radio "){
if (radioObj[i].value == intValue){
radioObj[i].checked = true;
}else{
radioObj[i].checked = false;
}
}
}
}
</script>
<body>
<INPUT TYPE= "radio " NAME= " " value= "1 "> 1
<INPUT TYPE= "radio " NAME= " " value= "1 "> 1
<INPUT TYPE= "radio " NAME= " " value= "1 "> 1
<INPUT TYPE= "radio " NAME= " " value= "1 "> 1
<INPUT TYPE= "radio " NAME= " " value= "1 "> 1
<INPUT TYPE= "radio " NAME= " " value= "1 "> 1
<INPUT TYPE= "radio " NAME= " " value= "1 "> 1
<INPUT TYPE= "radio " NAME= " " value= "2 "> 2
<INPUT TYPE= "radio " NAME= " " value= "2 "> 2
<INPUT TYPE= "radio " NAME= " " value= "2 "> 2
<INPUT TYPE= "radio " NAME= " " value= "2 "> 2
<INPUT TYPE= "radio " NAME= " " value= "1 "> 1
<INPUT TYPE= "radio " NAME= " " value= "2 "> 2
<INPUT TYPE= "radio " NAME= " " value= "2 "> 2
<INPUT TYPE= "button " value= "单选1 " onclick= "_check(1); "> <INPUT TYPE= "button " value= "单选2 " onclick= "_check(2); ">
</body>