获取RadioButtonList选中值

zp63534036 2010-04-06 11:28:45
想请教一个简单的问题,就是在asp中的RadioButtonList控件获取选中值的问题
...全文
86 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
zp63534036 2010-04-06
  • 打赏
  • 举报
回复
谢谢,可以了
wgale025 2010-04-06
  • 打赏
  • 举报
回复
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>

<asp:RadioButtonList id="rbl" runat="SERVER">
<asp:ListItem selected="true">男</asp:ListItem>
<asp:ListItem>女</asp:ListItem>
</asp:RadioButtonList>
<input type="button" value="test" onclick="test();" />
</div>
</form>
<script type="text/javascript">
function test() {
var arr = document.getElementById("rbl").getElementsByTagName("input");
for (var i = 0; i < arr.length; i++) {
if (arr[i].checked) {
alert(arr[i].value);
}
}
}
</script>
</body>
</html>
zp63534036 2010-04-06
  • 打赏
  • 举报
回复
额,不好意思,是asp.net的,我想在JS里面获取它的选中值要怎么写?
wgale025 2010-04-06
  • 打赏
  • 举报
回复
RadioButtonList应该是asp.net里面的吧。
比如:
<asp:RadioButtonList id="rbl" runat="SERVER">
<asp:ListItem selected="true">男</asp:ListItem>
<asp:ListItem>女</asp:ListItem>
</asp:RadioButtonList>
获取选中项: rbl.SelectedValue;
或者遍历一下:
foreach(ListItem li in rbl.Items){
if(li.Selected){
Response.Write(li.value + " "+ li.Text);
}
}

87,910

社区成员

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

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