问题
After selecting an item in the autocomplete list, my script validates the selection but does not release the focus. Ive even tried to place focus on another element to my dissapointment.
This is my code:
var usernames = [<? print_r($jquery_usernames); ?>];
$("#suggest1").autocomplete(usernames);
$("#suggest1").result(function() {
$(this).submit();
setTimeout(function() {
$('#focusdiv').focus();
}, 1);
});
Any suggestions?
回答1:
This is interesting and works (the focus is removed from the suggest1 input):
$("#suggest1").autocomplete(usernames);
$("#suggest1").result(function() {
$(this).submit();
setTimeout(function() {
$('.next-step').focus();
}, 1);
});
Note: It doesnt work without the setTimeout function. '.next-step' is a clickable href (tabbed form)
回答2:
Can you use the blur event? I.E. $('#suggest1').blur();
来源:https://stackoverflow.com/questions/5834990/jquery-autocomplete-remove-focus-after-suggest