获取RadioButton选中的值

时间:2022-02-26 00:01:44

1.RadioButtonList的RepeatDirection="Horizontal"可以设置按扭选项横对齐;

2.获取选中的RadioButton值;

$("#<%=rbA.ClientID %>").find("input[type='radio']:checked").val();

实例:当点击按扭为是时文本框可用,否则不可用

代码:

 <html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="../Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
//获取rbA选中的值
var s = $("#<%=rbA.ClientID %>").find("input[type='radio']:checked").val();
//当选【是】时文本框可填,选【否】文本框禁用
$("#<%=rbA.ClientID %>").find("input[type='radio']").click(function () {
var currentCheckedVal = $(this).val();//获取当前选中的值
if (currentCheckedVal == ) {//如果为【是】
$("#<%=txtName.ClientID %>").attr("disabled", "");
}
else if (currentCheckedVal == ) {//选中的是【否】
$("#<%=txtName.ClientID %>").attr("disabled", "disabled");
$("#<%=txtName.ClientID %>").val("");
}
});
});
function funCheck() {
var ss = $("#<%=rbA.ClientID %> input[type='radio']:checked").val();
alert(ss);
};
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:RadioButtonList runat="server" ID="rbA" RepeatDirection="Horizontal" style="float:left;">
<asp:ListItem Value="">是</asp:ListItem>
<asp:ListItem Value="" >否</asp:ListItem>
</asp:RadioButtonList><span style="color: #ff0000;float:left;">*</span>
<asp:TextBox ID="txtName" runat="server" ></asp:TextBox>
<asp:Button ID="btnSave" runat="server" Text="保 存" onclick="btnSave_Click" OnClientClick="return funCheck()" />
</div>
</form>
</body>
</html>