在JavaScript中如何获得一组radio中选中的value?

lwd2k 2003-08-20 10:46:03
...全文
58 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
anita2li 2003-08-20
  • 打赏
  • 举报
回复
<form id="frmEdit1">
<input type="radio" name="rtest" value="1">1
<input type="radio" name="rtest" value="2">2
<input type="radio" name="rtest" value="3">3
<input type="button" value="check_radio" onclick="check_r();">
</form>

<Script Language="JavaScript">
function check_r()
{
for(var i=0;i<document.all("rtest").length;i++)
{
if(document.all("rtest")(i).checked)
alert(document.all("rtest")(i).value);
}
}
</Script>
flyycyu 2003-08-20
  • 打赏
  • 举报
回复
radio的名字必须一致,然后用数组来检查
zhaoweiwei 2003-08-20
  • 打赏
  • 举报
回复
<form id="frmEdit1">
<input type="radio" name="rtest" value="1">1
<input type="radio" name="rtest" value="2">2
<input type="radio" name="rtest" value="3">3
<input type="button" value="check_radio" onclick="check_r();">
</form>

<script>
function check_r()
{
var a=document.getElementsByName("rtest")
for(var i=0;i<a.length-1;i++)
{
if(a[i].checked)
{alert(a[i].value)}
}
</script>

87,910

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧