YUI 自动完成:粘贴后搜索?
我使用 YUI 中的自动完成小部件来实现实时搜索,如示例中所示。 但是,在输入搜索文本时它可以正常工作,但在将文本粘贴到字段中时则无法工作。 哪种方法是在粘贴时启动自动完成功能的正确方法? 在文档中没有找到任何相关内容...
编辑:粘贴不是 Ctrl-V,它通常是上下文菜单中的“粘贴”。 YUI 确实会对按键做出反应,但如果通过鼠标粘贴任何内容,则不会做出反应。
I'm using an auto-complete widget from YUI to implement live search as in the examples. However, it works fine when search text is typed in, but fails to work when the text is pasted into the field. Which would be the proper way to initiate an autocompletion on paste? Haven't found anything for that in the documentation...
EDIT: Pasting is not Ctrl-V, it's usually "Paste" from the context-menu. YUI does react to a keypress, but doesn't if anything is pasted by the mouse.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我们扩展了 YUI 的自动完成小部件,并以这种方式处理上下文菜单中的粘贴:
其中
this
是自动完成小部件。We have extended YUI's autocomplete widget and handle paste from the context menu in this way:
Where
this
is the autocomplete widget.也许在按键事件中,您可以检测他们是否在按住 ctrl 的同时按下了 v。 如果有,则执行 sendQuery('query=' + textInput.value);
Perhaps on key event, you could detect if they pressed v while holding ctrl. If they have, then do a sendQuery('query=' + textInput.value);
编辑
这是一个兼容性表,显示哪些浏览器允许您订阅粘贴事件。
http://www.quirksmode.org/dom/events/cutcopypaste.html
这是他的测试页面,您可以在其中查看如何订阅事件。
http://www.quirksmode.org/dom/events/tests/cutcopypaste。 我想
你可以使用 YUI & 来订阅它。 然后让你的回调是这样的:
注意浏览器不兼容,看起来有些事件的实现很奇怪。
Edit
Here's a compatibility table showing which browsers let you subscribe to the paste events.
http://www.quirksmode.org/dom/events/cutcopypaste.html
Here's his testing page where you can see how to subscribe to the events.
http://www.quirksmode.org/dom/events/tests/cutcopypaste.html
I imagine you could subscribe to that using YUI & then just have your callback be this:
Watch out for browser incompatibilities, looks like some have a weird implementation of the events.