最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

jquery - Which event raised when set value of input in JavaScript - Stack Overflow

programmeradmin2浏览0评论

When set value of input in JavaScript which event raised? I tried these event: (propertychange change keypress paste focus textInput input keyup keydown change). For example:

$('input').live/bind/on('which event', function() {
    //...
});
$('input')[0].value = "sd";

When set value of input in JavaScript which event raised? I tried these event: (propertychange change keypress paste focus textInput input keyup keydown change). For example:

$('input').live/bind/on('which event', function() {
    //...
});
$('input')[0].value = "sd";
Share Improve this question edited Oct 14, 2022 at 18:15 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Aug 27, 2013 at 12:26 Abbas BafekrAbbas Bafekr 631 gold badge1 silver badge6 bronze badges 3
  • 1 Are you perhaps looking for the change event? – Lix Commented Aug 27, 2013 at 12:28
  • Since you're doing it programatically, why not just run whatever function you need when setting the input's value? – BenM Commented Aug 27, 2013 at 12:28
  • 2 No event is raised when you change the value programmatically (except propertychange, which is non-standard). Consider raising your own event after performing the change operation. – Frédéric Hamidi Commented Aug 27, 2013 at 12:29
Add a ment  | 

3 Answers 3

Reset to default 5

When you set the value programmatically no event will be raised. You can raise it yourself though:

$('input')[0].value = "sd";
$('input').first().trigger("change");

Or just using jQuery:

$('input').first().val("sd").trigger("change");

You can do something like this. You have to explicitly call change event.

$('input').val('New Value').change();

When a value is changed via a script the change event is not fired, if you want to run a handler then you can trigger the event manually

$('input').eq(0).val("sd").trigger('change');
发布评论

评论列表(0)

  1. 暂无评论