我在form中的radiobutton1中设置value为10,但在javascript中用document.myform.radiobutton1.value引用的时候,怎么会是"undefine"呢? how many radios named "radiobutton1" do you have? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 给你一个在本页中取得“radio”项值的方法:<html><head><meta http-equiv="Content-Language" content="zh-cn"><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><meta name="GENERATOR" content="Microsoft FrontPage 4.0"><meta name="ProgId" content="FrontPage.Editor.Document"><title>Radio's Value</title></head><body><form method="POST" action="--WEBBOT-SELF--"> <input type="radio" value="a" name="R1" onclick="document.all.radiovalue.value=this.value;">a <input type="radio" value="b" name="R1" onclick="document.all.radiovalue.value=this.value;">b <input type="button" value="提交" name="B1" onclick="if (document.all.radiovalue.value=='') alert('您还没有选中任一项'); else alert(document.all.radiovalue.value);"> <input type="hidden" value="" name=radiovalue> </form></body></html> document.myform.radiobutton1一般是个数组:你可以这样:for(var i =0;i<document.myform.radiobutton1.length;i++){if(document.myform.radiobutton1[i].checked) alert(document.myform.radiobutton1[i].value)} <script>function a(){for(var i =0;i<document.myform.radiobutton1.length;i++){if(document.myform.radiobutton1[i].checked) alert(document.myform.radiobutton1[i].value)} }</script><form name=myform><input type=radio name="radiobutton1" value="a"><input type=radio name="radiobutton1" value="b"><input type=radio name="radiobutton1" value="c"><input type=radio name="radiobutton1" value="d"><input type=button onclick="a()" value="get"></form> 另外对只有一个radiobutton的时候要单独处理 如果只有一个radiobutton1,可以用document.myform.radiobutton1.value如果多个,就要用遍历数组了<form name=myform><input type=radio name=radiobutton1 value=1><input type=radio name=radiobutton1 value=2><input type=button onclick=check()></form><script>function check(theForm){var o=document.myform.all("radiobutton1")if(o.length)for(i=0;i<o.length;i++){if(o[i].checked){alert(o[i].value);return;}}elseif(o.checked){alert(o.value);return;}alert('您还没有选中任一项');}</script> 上传图片预览问题 javascript中的继承, 找回丢失的constructor 在线请教。怎样让三张图片交替显示 跪求一观看图片的js特效代码 求网站上在一个表格里显示多张图片 锁定页面 XMLHTTP 如何更好的处理无闪 window 对象有 parent 也就是它的父窗口.怎么判断一个 window 有没有 parent 也就是怎么判断一个 window 是不是最上层的 window 呢? jquery点击标签下面的表格显示及隐藏 如何得到表格的最后一个td的id 高手请进, 请所有人进来看看,能解决的送500分!
<html><head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>Radio's Value</title>
</head>
<body>
<form method="POST" action="--WEBBOT-SELF--">
<input type="radio" value="a" name="R1" onclick="document.all.radiovalue.value=this.value;">a
<input type="radio" value="b" name="R1" onclick="document.all.radiovalue.value=this.value;">b
<input type="button" value="提交" name="B1" onclick="if (document.all.radiovalue.value=='') alert('您还没有选中任一项'); else alert(document.all.radiovalue.value);">
<input type="hidden" value="" name=radiovalue>
</form>
</body>
</html>
for(var i =0;i<document.myform.radiobutton1.length;i++)
{
if(document.myform.radiobutton1[i].checked) alert(document.myform.radiobutton1[i].value)
}
function a()
{
for(var i =0;i<document.myform.radiobutton1.length;i++)
{
if(document.myform.radiobutton1[i].checked) alert(document.myform.radiobutton1[i].value)
}
}
</script>
<form name=myform>
<input type=radio name="radiobutton1" value="a">
<input type=radio name="radiobutton1" value="b">
<input type=radio name="radiobutton1" value="c">
<input type=radio name="radiobutton1" value="d">
<input type=button onclick="a()" value="get">
</form>
如果多个,就要用遍历数组了
<form name=myform>
<input type=radio name=radiobutton1 value=1>
<input type=radio name=radiobutton1 value=2>
<input type=button onclick=check()>
</form>
<script>
function check(theForm){
var o=document.myform.all("radiobutton1")
if(o.length)
for(i=0;i<o.length;i++){if(o[i].checked){alert(o[i].value);return;}}
else
if(o.checked){alert(o.value);return;}
alert('您还没有选中任一项');
}
</script>