开发者

jQuery change event after setting value via document.getElementById(...).value

I'm trying to handle change event, but it seems it doesn't work. I would like to handle the event using jQuery after setting value via document.getElementById('id_of_input').value开发者_如何学JAVA. Here is the code: http://jsbin.com/axagej (to edit see: http://jsbin.com/axagej/edit) - I would like to see an alert.


The change event is working fine for me. It's just acting when you lost focus. If you prefer alert while writing, you should be interested by the jQuery keyboard events (http://api.jquery.com/category/events/keyboard-events/).

@tchaOo


If you're setting the value programatically you need to fire the event yourself using change or trigger:

$("#sample").change();

or

$("#sample").trigger("change");


When you're programmatically changing the value of a field, you won't get a change event. You'll need to explicitly invoke the change handler. See the updated jsbin: http://jsbin.com/axagej/2/edit

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜