Ctrl + V(粘贴)触发jQuery的键入功能TWICE [英] Ctrl+V ( Paste ) triggers jQuery's keyup function TWICE

查看:530
本文介绍了Ctrl + V(粘贴)触发jQuery的键入功能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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆