jQuery UI 自动完成:如何获取“更改”事件要提前触发吗?
http://jqueryui.com/demos/autocomplete/#event-change
听起来就像 change
事件应该在您选择一个项目后触发,但它似乎会触发 onblur,但前提是输入已更改。
select
OTOH 触发得太早,它在输入文本更新之前触发。
我想在用户选择一个项目后或在用户键入某些内容并切换焦点后(如通常的更改事件)立即对输入执行某些操作。
我怎样才能做到这一点?
http://jqueryui.com/demos/autocomplete/#event-change
It sounds like the change
event is supposed to fire after you've selected an item, but instead it seems to fire onblur, but only if the input has changed.
select
OTOH fires too early, it fires before the input text gets updated.
I want to do something with the input as soon as the user picks an item OR after the user types something and switches focus (like the usual change event).
How can I do that?
没关系,想通了。我们可以作弊:
手动设置输入的值,然后手动触发更改事件,并返回 false,这样就不必设置两次输入了。
Nevermind, figured it out. We can cheat:
Set the value of the input manually, then trigger the change event manually, and return false so that it doesn't bother setting the input twice.