zoukankan      html  css  js  c++  java
  • 获取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
  • 相关阅读:
    The 16th Zhejiang Provincial Collegiate Programming Contest Sponsored(E F G H I)
    Ubuntu iso下载地址(14、16、18)
    JS解决在提交form表单时某个值不存在 alter弹窗点确定不刷新界面
    搞搞电脑微信表情的破解(.dat转png or jpg)
    12.29 模拟赛
    bzoj 2151 种树
    bzoj 5110 Yazid的新生舞会
    【系列】 点分治
    12.8 模拟赛
    12.17 模拟赛
  • 原文地址:https://www.cnblogs.com/huangzhen22/p/3257992.html
Copyright © 2011-2022 走看看