获取RadioButton选中的值

博客介绍了如何在网页中实现RadioButton选项横对齐,并通过JavaScript获取选中的RadioButton值。示例展示了当用户选择'是'时,文本框将变为可用状态,否则保持禁用。代码来源于网络。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

2.获取选中的RadioButton值;

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

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

代码:

 1 <html xmlns="http://www.w3.org/1999/xhtml">
 2 <head runat="server">
 3     <title></title>
 4     <script src="../Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
 5     <script type="text/javascript">
 6         $(document).ready(function () {
 7             //获取rbA选中的值
 8             var s = $("#<%=rbA.ClientID %>").find("input[type='radio']:checked").val();
 9             //当选【是】时文本框可填,选【否】文本框禁用
10             $("#<%=rbA.ClientID %>").find("input[type='radio']").click(function () {
11                 var currentCheckedVal = $(this).val();//获取当前选中的值
12                 if (currentCheckedVal == 1) {//如果为【是】
13                     $("#<%=txtName.ClientID %>").attr("disabled", "");
14                 }
15                 else if (currentCheckedVal == 0) {//选中的是【否】
16                     $("#<%=txtName.ClientID %>").attr("disabled", "disabled");
17                     $("#<%=txtName.ClientID %>").val("");
18                 }
19             });
20         });
21         function funCheck() {
22             var ss = $("#<%=rbA.ClientID %> input[type='radio']:checked").val();
23             alert(ss);
24         };
25     </script>
26 </head>
27 <body>
28     <form id="form1" runat="server">
29     <div>
30         <asp:RadioButtonList runat="server" ID="rbA" RepeatDirection="Horizontal" style="float:left;">
31             <asp:ListItem Value="1">是</asp:ListItem>
32             <asp:ListItem Value="0" >否</asp:ListItem>
33         </asp:RadioButtonList><span style="color: #ff0000;float:left;">*</span>
34         <asp:TextBox ID="txtName" runat="server" ></asp:TextBox>
35         <asp:Button ID="btnSave" runat="server" Text="保  存" onclick="btnSave_Click" OnClientClick="return funCheck()"  />
36     </div>
37     </form>
38 </body>
39 </html>
View Code

 

转载于:https://www.cnblogs.com/huangzhen22/p/3257992.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值