当我用鼠标粘贴文本时,为什么我的文本框字数统计代码不起作用?

发布于 2024-12-21 11:56:25 字数 403 浏览 6 评论 0原文

我在我的应用程序中使用 jQuery。

我在一个函数上组合使用了 Keyup 和 Change 事件。即我有一个文本框,每当我在其中输入时,字数统计就会出现在它的顶部。所以基本上我有字数统计功能,适用于 KeyupChange 事件。

问题是,当我使用鼠标在文本框中粘贴一些文本时,计数不会改变,除非我按某个键或单击其他地方。

这是我的代码:

events :
'keyup #IdOfTextbox'  : 'wordCounter'
'change #IdOfTextbox'  : 'wordCounter'
wordCounter() : =>
//Code for counting words in Text Box

I am using jQuery for my application.

I have used Keyup and Change events combined on a function. i.e. I have a textbox and whenever I type in it the word counts comes on top of it. So basically I have word count function which works on Keyup and Change events.

The problem is when I use mouse to paste some text in text box the count doesn't changes unless I press some key or I click elsewhere.

Here is my code :

events :
'keyup #IdOfTextbox'  : 'wordCounter'
'change #IdOfTextbox'  : 'wordCounter'
wordCounter() : =>
//Code for counting words in Text Box

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

压抑⊿情绪 2024-12-28 11:56:25

请尝试以下操作:

$(document).ready(function(){
    $(".test").bind("paste keyup change", function() {
        console.log($(this).val().length);
    });
});

Try the following:

$(document).ready(function(){
    $(".test").bind("paste keyup change", function() {
        console.log($(this).val().length);
    });
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文