Ctrl + V(粘贴)触发jQuery的键入功能TWICE [英] Ctrl+V ( Paste ) triggers jQuery's keyup function TWICE
问题描述
如何使 Ctrl + V 或粘贴"不触发keyup
函数TWICE?
How to make Ctrl+V or Paste not trigger the keyup
function TWICE?
这对我来说是个问题,因为我做了自动完成功能,当我粘贴到文本框中时,它两次显示相同的数据.我希望现在这更有意义.
This is a problem for me because I made an AutoComplete functionality, and it displays the same data twice when i paste in a textbox. I hope this makes more sense now.
好的,我发现了如何通过$('#this-id').bind('paste', function() {});
Okay guys, I have found out how to detect Ctrl+V by $('#this-id').bind('paste', function() {});
但是现在另一个后续问题是如何将其与keyup
组合在一起,以便在按下paste
时,keyup
不再触发.
But now another follow up question is how to combine it with keyup
so that when paste
is pressed, keyup
wont trigger anymore.
推荐答案
好的,谢谢大家的回答,但是当我阅读本书时,很多博客都说:"如果您正在实施自动完成功能,不要依赖键"功能"
Okay guys, Thank you all for your answers but as I go through some reading, a lot of blogs say this: "IF you're implementing an autocomplete functionality, DON'T rely on 'keyup' function"
所以我将代码更改为$('#this-id').bind('input', function() {});
它奏效了,我现在不必担心粘贴或其他任何事情.我希望这对其他人也有帮助.
And it worked, I don't have to worry now about pasting or anything else. I hope this helps to others too.
这篇关于Ctrl + V(粘贴)触发jQuery的键入功能TWICE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!