Chrome中的文本框未触发onChange事件 [英] onChange event not firing on a textbox in Chrome

查看:542
本文介绍了Chrome中的文本框未触发onChange事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码来绑定一些验证逻辑,以在用户更新文本框的值时触发.我希望//Do some stuff here代码在绑定到任何文本框时都将失去焦点.

I have the following code to bind some validation logic to be fired when a user updates the value of a textbox. I expect that the //Do some stuff here code will execute when any of the textboxes it is bound to lose focus.

function RegisterHoursValidationHandlers() {
    $('.topic-frame-body input[type=text]').live('change', function () {
        //Do some stuff here
    });
}

这完全符合我在IE,Firefox和Safari中的预期.但是,该事件从未在Chrome中触发,我也不知道为什么.

This works exactly as I expect in IE, Firefox and Safari. However, the event never fires in Chrome and I have no idea why.

更新:我可以通过将'change'更改为'blur'来获得所需的效果.尽管这仍然不能解释为什么它不与'change'冲突.

UPDATE: I was able to get the desired effect by changing 'change' to 'blur'. Though this still doesn't explain why it doesn't worh with 'change'.

推荐答案

没有已知的怪癖关于铬. (所有浏览器均支持change事件)

There's no known quirk about chrome. (the change event is supported across all browsers)

示例,其中实时展示了它可以处理动态内容.

在此处进行测试:

此处有一些信息或假设使此问题无法解决.

There is a piece of information or an assumption being made here that makes this unsolvable.

更新:如果将其更改为模糊时它可以工作,则可能覆盖了先前的事件或功能.通过将其更改为模糊,不再覆盖它,因为它是 另一个事件 .

UPDATE: If it works when you change it to blur, it is possible that you are overwriting the previous event or function. By changing it to blur, whatever is overwriting it no longer will because it is a a different event.

这还将解释为什么您没有看到任何错误. (请记住,我相信jQuery将链接绑定到相同元素的事件,但是live()有点特殊情况-但事实可能表明它是函数,而不是事件绑定)

这篇关于Chrome中的文本框未触发onChange事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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