获取RadioButton选中的值
生活随笔
收集整理的這篇文章主要介紹了
获取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="保 存" οnclick="btnSave_Click" OnClientClick="return funCheck()" /> 36 </div> 37 </form> 38 </body> 39 </html> View Code?
轉載于:https://www.cnblogs.com/huangzhen22/p/3257992.html
總結
以上是生活随笔為你收集整理的获取RadioButton选中的值的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: jsonp获取服务器数据的方式
- 下一篇: VMware vSphere@cloud