问题
http://community.sciencecareers.org/mt-static/plugins/CommunityPlus/js/autocomplete/ http://community.sciencecareers.org/mt-static/plugins/CommunityPlus/js/autocomplete/demo/
Trying to programmatically trigger the display of the autocompletion list results. This, instead of waiting for user input.
Is this doable? (I've tried getting the element's focus, calling a Javascript down-arrow key event. No dice)
回答1:
If, and only if, you are using a version of jQuery 1.3 or greater, you can create a jQuery.Event object, then trigger()
it. I was only able to get it to work if the element is also focused. So this code works for the "E-Mail (local):" example on the demo page.
var e = jQuery.Event("keydown");
e.which = 40;
$('#suggest13').trigger('focus').attr('value',' ').trigger(e);
I'm not sure exactly what your situation is, I think it's somewhat dependent on the autocomplete actually showing something if only a space is pressed. That's not always the case.
回答2:
and what about this? $("#autocompleteid").autocomplete("search")
回答3:
$("#mainCombo_input").trigger('keydown.autocomplete'); will open the autocomplete div and also to display the dropdown.
And you can also use
$("#mainCombo_input").val("Item1");
$("#mainCombo_input").trigger('keydown.autocomplete'); to open div with on
回答4:
Per documentation, you can trigger a search (also mentioned in other answer). Since your case is on page load and it might not have any data on the input field you'll need to change minLength before an empty search can be ran:
$yourInputField.autocomplete('option', 'minLength', 0);
$yourInputField.autocomplete('search', "");
来源:https://stackoverflow.com/questions/1823617/how-do-i-have-jquerys-autocomplete-plugin-display-its-dropdown-list-upon-page-l