我正在使用来自YUI的自动完成小部件来实现实时搜索,如示例中所示。但是,当输入搜索文本时,它可以正常工作,但在将文本粘贴到字段时无法工作。这将是在paste上启动自动完成的正确方法?在文档中找不到任何内容...YUI自动完成:粘贴后搜索?
编辑:粘贴不是Ctrl-V,它通常是上下文菜单中的“粘贴”。 YUI确实会对按键做出反应,但如果粘贴的鼠标,则不会发生任何反应。
我正在使用来自YUI的自动完成小部件来实现实时搜索,如示例中所示。但是,当输入搜索文本时,它可以正常工作,但在将文本粘贴到字段时无法工作。这将是在paste上启动自动完成的正确方法?在文档中找不到任何内容...YUI自动完成:粘贴后搜索?
编辑:粘贴不是Ctrl-V,它通常是上下文菜单中的“粘贴”。 YUI确实会对按键做出反应,但如果粘贴的鼠标,则不会发生任何反应。
也许在关键事件中,您可以检测到按住ctrl时是否按下了v。如果他们有,那么做一个sendQuery('query ='+ textInput.value);
编辑
这里是一个兼容性表,显示该浏览器让你订阅粘贴事件。
http://www.quirksmode.org/dom/events/cutcopypaste.html
这是他的测试页面,在这里你可以看到如何订阅事件。
http://www.quirksmode.org/dom/events/tests/cutcopypaste.html
我想你可以订阅,使用YUI &然后只是有回调是这样的:
function() {
autoCompleteObject.sendQuery(autoCompleteElement.value);
}
留意浏览器不兼容,貌似有些有一个奇怪的执行活动。
我们已经扩展YUI的自动完成构件和处理从上下文菜单中选择以这种方式粘贴:
YAHOO.util.Event.on(input, 'paste', function(e, autocomplete) {
// We're interested in the value of the input field after text is pasted into
// it instead of the pasted text because the autocomplete proposals are based
// upon the field's whole value. The paste event happens before the input
// field has been updated so we need to wait until after this event has been
// handled to check the value of the input field.
window.setTimeout(function() {
if (autocomplete._sInitInputValue !== autocomplete.getInputEl().value) {
autocomplete.sendQuery(autocomplete.getInputEl().value);
}
}, 1);
}, this);
哪里this
是自动完成构件。
您也可以使用['YAHOO.lang.later'](http://developer.yahoo.com/yui/docs/YAHOO.lang.html)而不是'window.setTimeout'。 – 2010-11-06 08:00:34