我想知道是否有人偶然发现了这个问题。
我在同一页面上有两个asp:RadioButtonList
控件。我通过jQuery给了他们两个点击事件(见下文)。
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
时,所选值与第一个选定值保持一致。
如何解决此问题?
答案 0 :(得分:1)
我找到了解决方案。
我只需要改变搜索jQuery选择值的方式 而不是:
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();