为什么在预粘贴时将事件粘贴到jquery会触发? [英] Why Paste Event in jquery fires on pre-paste?

查看:96
本文介绍了为什么在预粘贴时将事件粘贴到jquery会触发?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作类似于 Twitter 的文本框,为此我编写了代码

I am trying to make textbox similar to the Twitter, for this i have written code for


  • 字数

  • 使用的事件更改,密钥和粘贴

密钥和更改事件工作正常但粘贴事件有点奇怪,当我在textarea中粘贴一些东西时,字数不会在那一刻发生变化,经过一些调试后我发现粘贴事件在粘贴文本框上的内容之前会激活。我不知道他们是如何处理Twitter的。
这是我的代码:
events:

Keyup and Change Events are working fine but paste event is little bit strange, when i paste something in textarea the word count doesn't change at that moment, after some debugging i found that paste event fires up before pasting something on textbox. I don't know how they handle this in Twitter. Here is my code : events:

'click #textboxId'  : 'submitQuestion'
'keyup #textboxId'  : 'wordCounter'
'change #textboxId' : 'wordCounter'
'paste #textboxId'  : 'wordCounter'

wordCounter: ->  
  #Code for Word Count#  

由于粘贴事件的预粘贴性质,工作count不会在该实例上发生变化。

您的建议和帮助将不胜感激,感谢您的时间。

Due to pre-paste nature of paste event the work count doesn't changes on that instance.
Your suggestion and help will be appreciated, Thanks for your time.

推荐答案

请参阅此示例。

http://jsfiddle.net/urEhK / 1

$('textarea').bind('input propertychange', function() {
    $('#output').html($(this).val().length + ' characters');
});

这种行为非常奇怪。您会认为其中一个事件能够正确捕捉到这一点吗?令我感到惊讶的是,谷歌没有更多答案。

That behavior was very weird. You would think that one of those events would catch this properly? I was surprised there weren't more answers to this via Google.

这篇关于为什么在预粘贴时将事件粘贴到jquery会触发?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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