捕获粘贴事件
我需要一份副本&粘贴事件。我有一个例子。但粘贴事件会触发 4 次。为什么?我需要一次。这是代码吗?请帮我?
$(function() {
return $('#myform').bind('paste', function(e) {
return alert("123");
});
});
I need a catch copy & paste event. I have a example. But paste event fires 4 times. Why? I need a it a one time. Here is the code? Please help me?
$(function() {
return $('#myform').bind('paste', function(e) {
return alert("123");
});
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定您的浏览器经历了四个事件被触发,但我刚刚亲自测试了您的代码,但无法重现该行为。话虽这么说,您的代码存在一些问题...
绑定事件后无需
返回
jQuery 对象。无需
返回alert()
,因为alert
返回undefined
。看看这些变化:
查看实时:http://jsfiddle.net/rwaldron/6CKxM/
I'm not sure which browser your experience four events being fired, but I've jus tested your code for myself and could not reproduce the behaviour. That being said, there are a few issues with your code as it is...
There is no need to
return
the jQuery object after binding the event.There is no need to
return alert()
, sincealert
returnsundefined
.Take a look at these changes:
See live: http://jsfiddle.net/rwaldron/6CKxM/