I've got a few dropdown lists which are created dynamically.
I've done a decent job of keeping my code DRY, but I have a small problem.
I instruct jQuery to trigger an event when a select list 'changes', and seeing as the list are built dynamically, they change when a response is retrieved from the server, which jQuery is considering a change. But what I actually want is for the action to be triggered only when an option is 'selected' from the dropdown list.
$('select').change(function(){
var idx = $(this).index();
var query = $(this).val();
$.ajax({
url: 'getNext',
data: {query:query},
dataType: 'json',
success: function(data){
var optionsList ='';
for (var j=0; j'+data[j]+'';
}
$('select:eq('+idx+1+')').html(optionsList);
}
});
});
I've tried using
$('select:selected').change()
but that doesn't trigger anything. Any suggestions on how to only trigger change when an option is selected, n开发者_如何学编程ot when an option or select list is created?Have you tried:
$('select').click(
function(){
$(this).trigger('change');
});
Try trigger
$('select:selected').trigger('change');
加载中,请稍侯......
精彩评论