JAVASCRITP 获取radio的值?? 可以改成:var obj = document.getElementsByName("type"+i); 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 var obj = eval("document.form1.type" + i); 你打印:var obj=document.form1.("type"+i).length你发现问题在哪了 var obj=document.forms["form1"]["type"+i]; 给出的代码都是错的,我给改了一下<script>function getvalue(i){ var obj=document.forms["form1"]["type"+i]; for(j=0;j <3;j++){ if(obj[j].checked){ var value=obj[j].value; break; } } alert(value) return value;}</script> <form name=form1> <input type="radio" name='type0' value=1 /> <input type="radio" name='type0' value=2 /> <input type="radio" name='type0' value=3 /> <input type="radio" name='type1' value=1 /> <input type="radio" name='type1' value=2 /> <input type="radio" name='type1' value=3 /> <input type="radio" name='type2' value=1 /> <input type="radio" name='type2' value=2 /> <input type="radio" name='type2' value=3 /></form><button onclick="getvalue(0)">getvalue</button> 用eval()。var obj=eval("document.form1.type"+i); <form name=form1> <input type="radio" name='type0' value=1 />01</input> <input type="radio" name='type0' value=2 />02</input> <input type="radio" name='type0' value=3 />03</input> <input type="radio" name='type1' value=1 />11</input> <input type="radio" name='type1' value=2 />12</input> <input type="radio" name='type1' value=3 />13</input> <input type="radio" name='type2' value=1 />21</input> <input type="radio" name='type2' value=2 />22</input> <input type="radio" name='type2' value=3 />23</input><button onclick="alert(getvalue(0))">确定</button></form><script language=javascript>function getvalue(i){ var obj=eval("document.form1.type"+i); for(j=0;j <3;j++) { if(obj[i].checked) { var value = obj[i].value; break; } //if } //for return value; } </script> 简洁高效<script language="javascript" type="text/javascript">function getvalue(i){ for(var j=0;j<3;j++) { var o=document.getElementsByName("type"+i)[j]; if (o.checked) alert(o.value); else alert("还没有选择"); }} </script><form name=form1> <input type="radio" name='type0' value=1 /> <input type="radio" name='type0' value=2 /> <input type="radio" name='type0' value=3 /><input type="button" name="Submit" value="按钮1" onClick="javascript:getvalue(0);"> <input type="radio" name='type1' value=1 /> <input type="radio" name='type1' value=2 /> <input type="radio" name='type1' value=3 /><input type="button" name="Submit" value="按钮2" onClick="javascript:getvalue(1);"> <input type="radio" name='type2' value=1 /> <input type="radio" name='type2' value=2 /> <input type="radio" name='type2' value=3 /><input type="button" name="Submit" value="按钮3" onClick="javascript:getvalue(2);"></form> 问一个比较笨的问题,jsp的问题。 我有一段JS代码,需要把里面的广告链接去掉 jquery.autocomplete 插件遇到的问题 怎样获得浏览器的高度? 关于javascript new option()的问题; IE7 document.namespaces 报 unknown 如何用javascript脚本实现打开像window中的“选择文件”、“另存为”等文件对话框 为什么我不能使用onChang事件啊 高分!框架问题?谢谢! reset按钮的程序怎么出错了? 简单问题请教,任务栏显示鼠标位置问题. 怎样设置cookie的过期日期为永远不过期啊?
var obj=document.form1.("type"+i).length
你发现问题在哪了
function getvalue(i){
var obj=document.forms["form1"]["type"+i];
for(j=0;j <3;j++){
if(obj[j].checked){
var value=obj[j].value;
break;
}
}
alert(value)
return value;
}
</script>
<form name=form1> <input type="radio" name='type0' value=1 /> <input type="radio" name='type0' value=2 /> <input type="radio" name='type0' value=3 /> <input type="radio" name='type1' value=1 /> <input type="radio" name='type1' value=2 /> <input type="radio" name='type1' value=3 /> <input type="radio" name='type2' value=1 /> <input type="radio" name='type2' value=2 /> <input type="radio" name='type2' value=3 /></form><button onclick="getvalue(0)">getvalue</button>
<form name=form1>
<input type="radio" name='type0' value=1 />01</input>
<input type="radio" name='type0' value=2 />02</input>
<input type="radio" name='type0' value=3 />03</input> <input type="radio" name='type1' value=1 />11</input>
<input type="radio" name='type1' value=2 />12</input>
<input type="radio" name='type1' value=3 />13</input> <input type="radio" name='type2' value=1 />21</input>
<input type="radio" name='type2' value=2 />22</input>
<input type="radio" name='type2' value=3 />23</input>
<button onclick="alert(getvalue(0))">确定</button>
</form>
<script language=javascript>function getvalue(i)
{
var obj=eval("document.form1.type"+i);
for(j=0;j <3;j++)
{
if(obj[i].checked)
{
var value = obj[i].value;
break;
} //if
} //for
return value;
} </script>
function getvalue(i){
for(var j=0;j<3;j++)
{
var o=document.getElementsByName("type"+i)[j];
if (o.checked)
alert(o.value);
else
alert("还没有选择");
}
}
</script><form name=form1>
<input type="radio" name='type0' value=1 />
<input type="radio" name='type0' value=2 />
<input type="radio" name='type0' value=3 />
<input type="button" name="Submit" value="按钮1" onClick="javascript:getvalue(0);">
<input type="radio" name='type1' value=1 />
<input type="radio" name='type1' value=2 />
<input type="radio" name='type1' value=3 />
<input type="button" name="Submit" value="按钮2" onClick="javascript:getvalue(1);">
<input type="radio" name='type2' value=1 />
<input type="radio" name='type2' value=2 />
<input type="radio" name='type2' value=3 />
<input type="button" name="Submit" value="按钮3" onClick="javascript:getvalue(2);">
</form>