JSONP 请求后立即执行 myFunction
我有一个允许显示 Google 建议的脚本: JsFiddle
我想用第一个 li 执行一个函数项目由 ui 自动完成呈现,所以我这样做了:
$("input#term").keyup(function() {
DoMyFunction($('.ui-autocomplete li:first-child a').text(), true);
});
然而问题是,在 keyup---> 之间有一段时间。 request--->xml 缓存和 html 渲染由 ui 自动完成。这意味着当没有 html 列表时,我的函数(DoMyFunction)被触发,因此它不起作用。所以我的问题是:在缓存和处理请求后如何立即执行我的功能。设置计时器不起作用,因为需要考虑很多变量(每个用户带宽)。
I have a script which allows to display Google suggestions: JsFiddle
I want to do a function with the first li item rendered by the ui autocomplete, so I did this:
$("input#term").keyup(function() {
DoMyFunction($('.ui-autocomplete li:first-child a').text(), true);
});
The problem however is that there is a period of time between the keyup---> request--->xml cache and html rendering by the ui autocomplete. Which means the my function (DoMyFunction) is being triggered when there is no html list, hence it doesnt work. So my question is: How do I do my function right after the reqeust is cached and processed. Setting a timer wont work because there are to many variables to account for (ea user bandwidth).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据 jQuery UI 文档,有一个
open
事件打开建议菜单时会触发您必须执行以下操作:
As per the jQuery UI docs, there's an
open
event which is triggered when the suggestion menu is openedYou'll have to do something like this :