您的位置:首页 > Web前端 > JavaScript

如何用JavaScript判断radio是否选中

2009-06-20 02:40 507 查看
如何用JAVAScript判断radio是否选中 [已结帖,结帖人:sunhongxiang] .
[华 软 网]
编程论坛  楼主 在写JAVAScript的时候,如何判断单选按钮是否被选中,并且在什么时候调用,急啊!!!! .
[华 软 网]
编程论坛 1 个网友回答: if( xxx.checked )
...... .
[华 软 网]
编程论坛 2 个网友回答:
比如这样:

<script>
function check()
{
for(i=0;i <document.form1.r1.length;i++)
if(document.form1.r1[i].checked)
{alert(document.form1.r1[i].value);return;}
}
</script>

<form name=form1>
<input type=radio name=r1 value=1>
<input type=radio name=r1 value=2>
<input type=radio name=r1 value=3>
<input type=button onclick=check()>
</form> .
[华 软 网]
编程论坛 3 个网友回答: 可以在radio的onclick事件中判断是否选中 .
[华 软 网]
编程论坛 4 个网友回答: 我在这也问个,复选框也是一样的吧,但是如果要进行批量删除时(全选),这时是如何判断实现啊 .
[华 软 网]
编程论坛 5 个网友回答:

HTML code
<script>
function  check()
{
for(i=0;i <document.form1.r1.length;i++)
if(document.form1.r1[i].checked)
{alert(document.form1.r1[i].value);return;}
}
</script>

<form  name=form1>
<input  type=radio  name=r1  value=1>
<input  type=radio  name=r1  value=2>
<input  type=radio  name=r1  value=3>
<input  type=button  onclick=check()>
</form>
.
[华 软 网]
编程论坛 6 个网友回答: 循环判断 .
[华 软 网]
编程论坛 7 个网友回答:

HTML code
<script>
function  check()
{
for(i=0;i <document.form1.r1.length;i++)
if(document.form1.r1[i].checked)
{alert(document.form1.r1[i].value);return;}
}
</script>

<form  name=form1>
<input  type=radio  name=r1  value=1>
<input  type=radio  name=r1  value=2>
<input  type=radio  name=r1  value=3>
<input  type=button  onclick=check()>
</form>
.
[华 软 网]
编程论坛 8 个网友回答: checked属性 .
[华 软 网]
编程论坛 9 个网友回答: document.getElementById("ID").checked .
[华 软 网]
编程论坛 10 个网友回答:
引用 2 楼 rocketsuperman 的回复:

比如这样:

<script>
function check()
{
for(i=0;i <document.form1.r1.length;i++)
if(document.form1.r1[i].checked)
{alert(document.form1.r1[i].value);return;}
}
</script>

<form name=form1>
<input type=radio name=r1 value=1>
<input type=radio name=r1 value=2>
<input type=radio name=r1 value=3>
<input type=button onclic…

引用 2 楼 rocketsuperman 的回复:

比如这样:

<script>
function check()
{
for(i=0;i <document.form1.r1.length;i++)
if(document.form1.r1[i].checked)
{alert(document.form1.r1[i].value);return;}
}
</script>

<form name=form1>
<input type=radio name=r1 value=1>
<input type=radio name=r1 value=2>
<input type=radio name=r1 value=3>
<input type=button onclic…
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: