开发者

Event binding for keyboard input or change through javascript

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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜