获取RadioButton选中的值

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

 

posted @ 2013-08-14 18:35  黄忠  阅读(2337)  评论(0编辑  收藏  举报