开发者

onChange event not firing on a textbox in Chrome

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开发者_JAVA技巧 bound to lose focus.

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

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

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'.


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

Example with live showing it working against dynamic content.

Test it here:

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.

This would also explain why you are not seeing any errors. (keep in mind, I believe that jQuery will chain events bound to the same elements, but live() is a bit of a special case - but that fact might point to it being the function, not the event binding)


Try using .delegate() instead http://api.jquery.com/delegate/

I've tried you code in both FF and Chrome - http://jsfiddle.net/B3aRy/ - It worked in both. So maybe its an issue elsewhere in your code?


What version of Jquery are you using?

I can't see the issue myself, but .live does not support the "change" event until jquery 1.4+


Try:

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

With the quotes around 'text' as I have it. Worth a shot.

Or try:

$(".topic-frame-body input:text").live();

The point being, I think the problem is in the details of how you're targeting the input field, rather than in the method.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜