有 2 个单选按钮。根据您单击的那个,下拉框将加载该组数据。根据我单击的第一个,加载大约需要 1-2 秒,而另一个会立即加载。甚至来回点击。我想知道为什么,以及如何让它立即停止加载(很奇怪,我知道)。
$('#rblGenre').change( function() {
$('#ddlSpecificGenre').attr('disabled','disabled').html( '<option>Loading...</option>' )
var genre = $(this + ':checked').val();
$.ajax({
type: 'GET',
url: '../bookGenres.xml',
dataType: 'xml',
success: function( xml ) {
var xmlGenre = $(xml).find( genre );
$('#ddlSpecificGenre').removeAttr('disabled').children().remove();
xmlGenre.children().each( function() {
$('#ddlSpecificGenre').append( '<option>' + $(this).text() + '</option>' );
});
}
});
});
<asp:RadioButtonList ID='rblGenre' runat='server'>
<asp:ListItem Text='Fiction' Value='Fiction'></asp:ListItem>
<asp:ListItem Text='Non-Fiction' Value='Non-Fiction'></asp:ListItem>
</asp:RadioButtonList>
<asp:DropDownList ID='ddlSpecificGenre' runat='server' Enabled='false'>
<asp:ListItem Text='Choose a Genre' Selected='True'></asp:ListItem>
</asp:DropDownList>