无法使用jQuery获取Multiple asp:RadioButtonList的选定值 [英] Not able to get selected value for Multiple asp:RadioButtonList using jQuery

查看:60
本文介绍了无法使用jQuery获取Multiple asp:RadioButtonList的选定值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有人偶然发现了这个问题.

I wonder if someone has stumbled upon this problem.

我在同一页面上有两个asp:RadioButtonList控件.我通过jQuery给了他们两个click事件(见下文).

I have two asp:RadioButtonList controls on the same page. I gave them both a click event via jQuery (see below).

Default.aspx:

Default.aspx:

<asp:RadioButtonList ID = "rad_banner_type" runat = "server" >
   <asp:ListItem Value ="Picture" Text ="Image(.jpg .png .bpm)" />
   <asp:ListItem Value ="Code" Text ="Code" />
   <asp:ListItem Value ="Flash" Text ="Flash(.swf)" />
</asp:RadioButtonList>

jQuery:

function pageLoad() {
   //LINK TYPE
   $("#<%= rad_link_type.ClientID%>").change(function () {
     var rad_link_type = $("input[@name=<%=rad_link_type.ClientID%>]:radio:checked").val();

        switch (rad_link_type) {
           case "Email":
              //Do Something
              break;
           case "PDF":
              //Do Something
              break;
           case "Website":
              //Do Something
              break;
           default:
              //Do Something
              break;
        }
   });

   //PICTURE TYPE
   $("#<%= rad_banner_type.ClientID%>").click(function () {
      var rad_banner_type = $("input[@name=<%=rad_banner_type.ClientID%>]:radio:checked").val();


         switch (rad_banner_type) {
            case "Picture":
               //Do Something
               break;
            case "Code":
               //Do Something
               break;
            case "Flash":
                //Do Something
                break;
            default:
                //Do Something
                break;
         }

   });
}

我的问题是,当我单击第一个RadioButtonList时,选定的值是正确的,但是,当我单击第二个RadioButtonList时,选定的值将与第一个选定的值保持相同.

My problem is that when I click on the first RadioButtonList the selected value is correct, but as soon as I click on the second RadioButtonList the selected value stays the same as the first selected value.

如何解决此问题?

推荐答案

我找到了解决方案.

我只需要更改搜索jQuery选定值的方式 代替:

I just need to change the way i search for the jQuery selected value instead of:

var rad_link_type = $("input[@name=<%=rad_link_type.ClientID%>]:radio:checked").val();
var rad_banner_type = $("input[@name=<%=rad_banner_type.ClientID%>]:radio:checked").val();

我用过:

var rad_link_type = $('#<%= rad_link_type.ClientID%>').find(":checked").val();
var rad_banner_type = $('#<%= rad_banner_type.ClientID%>').find(":checked").val();

这篇关于无法使用jQuery获取Multiple asp:RadioButtonList的选定值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆