开发者

Why jQuery.val( value ) does not dispatch any event from the DOM element?

开发者 https://www.devze.com 2023-01-20 05:48 出处:网络
When we use the method jQuery.Val( value ) over a DOM element to change its value. Shouldn\'t the element d开发者_JS百科ispatch an event informing that its value has changed? -I though the event \'cha

When we use the method jQuery.Val( value ) over a DOM element to change its value.

Shouldn't the element d开发者_JS百科ispatch an event informing that its value has changed? -I though the event 'change' was going to be dispatched.

If it shouldn't why?

Live Demo


It's not dispatched, this just doesn't happen when it's programmatically changed. You are however free to fire the event when needed like this:

$('#Anne').val('Jenny').change();

You can test it here.

The reasoning? If the user changed something you may need to react, but if you changed something then you know what happened, and firing an event handler may be completely wasteful...so it's up to you to call that event handler if it's needed.

0

精彩评论

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