gpt4 book ai didi

javascript - YUI 自动完成 : search after pasting?

转载 作者:行者123 更新时间:2023-11-30 13:42:50 26 4
gpt4 key购买 nike

我正在使用 YUI 的自动完成小部件来实现示例中的实时搜索。但是,当输入搜索文本时它工作正常,但当文本被粘贴到字段中时它无法工作。哪种方法是在粘贴时启动自动完成的正确方法?尚未在文档中找到任何内容......

编辑: 粘贴不是 Ctrl-V,它通常是上下文菜单中的“粘贴”。 YUI 确实会对按键使用react,但如果通过鼠标 粘贴任何内容则不会。

最佳答案

我们扩展了 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 是自动完成小部件。

关于javascript - YUI 自动完成 : search after pasting?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1293414/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com