javascript判断 我有一个radiobuttonlist 我现在想用javascript 判断radiobuttonlist选项是否选中,这个应该怎么做 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 点击后传入this对象function ClickRadio(ob){ if(ob.value == "选项值") { ob.checked = true; }} 遍历控件,type=radio,if(checked)就可以了 document.getElementById("ralist").checked 不好意思看错了,看成单个radio了 <asp:RadioButtonList ID="rbl" runat="server" RepeatDirection="Horizontal"> <asp:ListItem Value="0">是</asp:ListItem> <asp:ListItem Value="1">否</asp:ListItem></asp:RadioButtonList><input id="Button4" type="button" onclick="rblSel()" value="button" /><script type="text/javascript"> function rblSel() { var obj =document.all.rbl; for(i=1;i<obj.length;i++) { alert(document.all.rbl[i].checked); } } </script> 在代码里写不行么?!if(this.RadioButtonList名.Items[0].Selected == true){} RadioBox有checked属性,检查它的状态值为true或false. 个人感觉连选择RadioButtonList都需要确定的话会比较不爽!回传不应该在RadioButtonList身上。 function IsRadChk(RadName)//RadName为RadioButtonList的ID{ var ischk=false; var RadobjArr= document.getElementById(RadName); for(var i=0;i<radobjArr.length;i++) { var Radobj=radobjArr[i]; if(Radobj.checked) { ischk=true; break; } } alert(ischk);} <html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title>无标题页</title> <style type="text/css"> .style2 { width: 300px; border-style: solid; border-width: 1px; border-color:Green; } </style> <script language="javascript" type="text/javascript"> function checkSelect() { var obj = document.getElementById("rbtnTest").rows.length; //alert(obj); for(i=0;i<obj;i++) { var item = "rbtnTest_" + i; if(document.getElementById(item).checked == true) { alert("您选中了:"document.getElementById(item).value); } } } </script></head><body> <form id="form1" runat="server"> <div><asp:RadioButtonList ID="rbtnTest" runat="server"> <asp:ListItem>0</asp:ListItem> <asp:ListItem>1</asp:ListItem> <asp:ListItem>2</asp:ListItem> <asp:ListItem>3</asp:ListItem> </asp:RadioButtonList> <input type="button" id="Test" name="Test" value="Test" onclick="checkSelect()" /> </div> </form></body></html>楼主可以使用这一段代码,本人经过测试可用。 关于 Drawing.Font emSize的单位 文件上传保存到mysql报错,请帮忙。。。 我在页面上放了个table,我想把数据库里面的数据放到这个表里面,不知该怎么做 asp.net的web控件,我很讨厌,同感请up 如何截取字符? 如何实现aspx网页中点击按钮打开指定物理路径的word文件和excel文件。 关于从类名字符串创建相应对象的问题,昨天弄了一个晚上都没有搞定,救命啊帅哥美女们! GridView问题,增加实现?在线等! 急! 写的用户登陆界面遇到的小问题 有无人要CRYSTAL REPORT 9中文版? asp 怎么取这个ID号
function ClickRadio(ob)
{
if(ob.value == "选项值")
{
ob.checked = true;
}
}
<asp:RadioButtonList ID="rbl" runat="server" RepeatDirection="Horizontal">
<asp:ListItem Value="0">是</asp:ListItem>
<asp:ListItem Value="1">否</asp:ListItem>
</asp:RadioButtonList>
<input id="Button4" type="button" onclick="rblSel()" value="button" /><script type="text/javascript">
function rblSel()
{
var obj =document.all.rbl;
for(i=1;i<obj.length;i++)
{
alert(document.all.rbl[i].checked);
}
}
</script>
if(this.RadioButtonList名.Items[0].Selected == true)
{
}
回传不应该在RadioButtonList身上。
function IsRadChk(RadName)//RadName为RadioButtonList的ID
{
var ischk=false;
var RadobjArr= document.getElementById(RadName);
for(var i=0;i<radobjArr.length;i++)
{
var Radobj=radobjArr[i];
if(Radobj.checked)
{
ischk=true;
break;
}
}
alert(ischk);
}
<head runat="server">
<title>无标题页</title>
<style type="text/css">
.style2
{
width: 300px;
border-style: solid;
border-width: 1px;
border-color:Green;
}
</style>
<script language="javascript" type="text/javascript">
function checkSelect()
{
var obj = document.getElementById("rbtnTest").rows.length;
//alert(obj);
for(i=0;i<obj;i++)
{
var item = "rbtnTest_" + i;
if(document.getElementById(item).checked == true)
{
alert("您选中了:"document.getElementById(item).value);
}
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:RadioButtonList ID="rbtnTest" runat="server">
<asp:ListItem>0</asp:ListItem>
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
</asp:RadioButtonList>
<input type="button" id="Test" name="Test" value="Test" onclick="checkSelect()" />
</div>
</form>
</body>
</html>
楼主可以使用这一段代码,本人经过测试可用。