我怎么有jQuery的自动完成插件显示在页面加载的下拉列表?

问题描述:

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.

这是可行的? (我试过获得元素的焦点,调用JavaScript向下箭头键的事件。没有骰子)

Is this doable? (I've tried getting the element's focus, calling a Javascript down-arrow key event. No dice)

如果,且仅当您正在使用一个版本的jQuery 1.3或以上,你可以创建一个的 jQuery.Event 对象,那么触发()它。我只能够得到它的工作,如果该元素也集中。所以这code作品为电子邮件(本地):的例子上的演示页。

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);

我不知道你的情况是什么,我认为这是一定程度上取决于实际显示的东西,如果只是一个空间pressed自动完成。这并非总是如此。

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.