'input propertychange'上的jQuery函数绑定不按预期触发 [英] jQuery function bind on 'input propertychange' not firing as expected

查看:1492
本文介绍了'input propertychange'上的jQuery函数绑定不按预期触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有调用函数的jQuery代码:

$ $ $'''text_area')。bind('input propertychange',function(){...

绑定到该函数的元素是一个文本区域。当我输入和删除文本时,函数被调用的很好,但是当我选择所有文本时,无论是通过热键还是拖动鼠标,然后回退,函数都不会被调用。我无法调用这个函数,这是预期的'input propertychange'事件吗?如果是这样,我该如何改变它以按预期工作?注意,这适用于对于Chrome,IE和Firefox。

解决方案

这会适合您的目的吗?
$ b $ ('keyup',function(){
console.log('called');
}) $('#text_area')。 ;

小提琴: HTTP:// jsfiddle.net/KyleMuir/ruJZD/



此外,截至jQuery 1.7 .on() http://api.jquery.com/on/ )是绑定事件的首选方式。


$ b 编辑:因为有人在右键单击粘贴文本后,这里是更新:



('keyup paste',function(){
console.log('called'); $($'$'$)
});

小提琴: http://jsfiddle.net/KyleMuir/ruJZD/9/


I have jQuery code that calls a function as such:

$('#text_area').bind('input propertychange', function() {...

The element being bound to the function is a text area. When I type and delete text the function gets called just fine, however when I select all of the text, either through a hot-key or dragging the mouse, and then hit backspace the function is not called. This is the only instance where I can not get the function to call. Is this expected with the 'input propertychange' event? If so how can I change this to work as expected? Note that this holds true for Chrome, IE, and Firefox.

解决方案

Would this suit your purposes?

$('#text_area').on('keyup', function() {
    console.log('called');
});

Fiddle: http://jsfiddle.net/KyleMuir/ruJZD/

Also, as of jQuery 1.7 .on() (http://api.jquery.com/on/) is the preferred way to bind events.

EDIT: since someone was after right click pasted text, here is an update:

$('#text_area').on('keyup paste', function() {
    console.log('called');
});

Fiddle: http://jsfiddle.net/KyleMuir/ruJZD/9/

这篇关于'input propertychange'上的jQuery函数绑定不按预期触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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