如果在键控上添加了字符,则Google Chrome更改输入事件不会被触发 [英] Google Chrome change event in input is not fired if char added on keyup

查看:107
本文介绍了如果在键控上添加了字符,则Google Chrome更改输入事件不会被触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

($ {$ b $ keyup:function(){
console.log('输入#不是工作')。 ');
$(this).val($(this).val()+'。'); //尝试任何其他字符
},
change:function() {
console.log('I'\\''ma changed input');
}
});

我在这个简化的 jsfiddle 的例子。
我的问题与此错误有关,我有一个正在构建的财务应用程序,如果输入数据发生更改,我需要显示保存更改按钮。因为我需要在 keyup (如果需要的话)上立即插入千位分隔符,所以这个错误真的让我感到困扰并且破坏了这个功能。



<要重现它,请转至 jsfiddle 示例,以chrome类型打开控制台,首先输入任何内容 keyup 事件将被正确触发,而不是使用标签的非焦点输入或在其外部单击,并且 change 事件不会被触发。与其他输入一样,并且 change 将被触发。



我在Firefox中测试了它,它按预期工作。

我使用的Chromium版本是14.0.835.202(开发人员构建103287 Linux)Ubuntu 11.10





尝试直接从Chrome网站直接安装Google Chrome 15.0.874.106。



我可以插入分隔符在 change 事件上,但由于用户将输入大量7位以上的数字,因此在输入分隔符时插入的分隔符会更好。

解决方案

我在IE9中试过它,它的行为和Chrome一样。



认为这是一个bug。



在HTML元素上使用.val(value)会重置手动更改标志,因此没有更改事件将会发生(因为用户不会手动更改 AFTER val()操作)。


$('input#not-gonna-work').bind({
    keyup: function(){
        console.log('Typed a key');
        $(this).val($(this).val() + '.');// try with any other char
    },
    change: function(){
       console.log('I\'m a changed input');
    }
});

I staged this bug in this simplified jsfiddle example. My problem related to this bug is that I have a financial app that I'm building and I need to display a "Save changes" button if input data is changed. Since I need to insert thousand separator immediately on keyup (if needed) this bug really annoys me and breakes that functionality.

To reproduce it go to jsfiddle example, open console in chrome type anything in first input, keyup event will be properly fired, than un-focus input with tab or clicking outside of it and change event won't be fired. Do the same with other input and change will be fired.

I tested this in Firefox and it works as expected.

Version of Chromium that I'm using is 14.0.835.202 (Developer Build 103287 Linux) Ubuntu 11.10

and

Tried with Google Chrome 15.0.874.106 freshly installed straight from Chrome website.

I could insert separators on change event, but since users will be entering lots of 7+ digits numbers it would much better UX to have separators inserted as they type.

解决方案

I tried it in IE9 and it has the same behavior as Chrome.

I don't think it's a bug.

Using .val(value) on an HTML element will reset the "manually changed" flag and thus no change event will occur (because the user doesn't change anything manually AFTER the val() operation).

这篇关于如果在键控上添加了字符,则Google Chrome更改输入事件不会被触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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