jquery 自动完成行为修改
我终于有了一些自动完成功能,但我想改变一种行为。如果用户输入部分值并单击返回列表之外的任何位置,则部分值将在输入中设置。如果用户没有选择返回的选项之一,我希望该值保持空白。
看起来焦点事件是我应该修改的,但我发现 API 令人困惑......它说:
Before focus is moved to an item (not selecting), ui.item refers to the focused
item. The default action of focus is to replace the text field's value with the
value of the focused item, though only if the focus event was triggered by a
keyboard interaction. Canceling this event prevents the value from being updated,
but does not prevent the menu item from being focused.
但它没有给出如何取消事件的示例。
I've got some autocompletes working finally, but there is one behavior I'd like to change. If the user types in a partial value and clicks anywhere outside of the list returned, the partial value gets set in the input. I would prefer that the value remain blank if the user doesn't select one of the returned options.
It looks like the focus event is what I should be modifying, but I find the API confusing... it says:
Before focus is moved to an item (not selecting), ui.item refers to the focused
item. The default action of focus is to replace the text field's value with the
value of the focused item, though only if the focus event was triggered by a
keyboard interaction. Canceling this event prevents the value from being updated,
but does not prevent the menu item from being focused.
but it doesn't give an example of how to cancel the event.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在另一个问题中找到了答案:)像这样修改更改事件似乎可以解决问题:
Found the answer in another question :) modifying the change event like so seems to do the trick: