我在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> js问题 jqgrid第一行和其他行布局不同如何解决。。。 关选checkbox选择 ====请教一个表格过滤问题,麻烦帮帮忙 :)===== 验证form的小问题 [求代码]可以自动算出两个时间的差,并显示的JAVASCRIPT代码 立即送分:几个select控件,name属性相同,如何知道用户操作激发了其中一个select的onchange()事件呢?我一定要知道是哪个select,如何实 谁知道亿唐网站的下拉菜单是如何做的? 跳转怎么写! 有关radio控制文本框显示的一个问题 高手请进, 请所有人进来看看,能解决的送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>