I have an input field with id myinput , and have change event bind to this field through,
$("input#myin开发者_JAVA技巧put").change(function(){
alert("the value is changed");
}
But the handler is not getting called, if I change the value through javascript
$("input#myinput").val(text);
But, it works if I enter the input through keyboard.
so, it seems like I am binding to wrong event. What should I do to bind to both keyboard input and JS value update (jQuery val() here).
thanks.
change is triggered only by user events. With jQuery you can use trigger('change') to trigger the change event programatically.
JS Fiddle demo.
加载中,请稍侯......
精彩评论