jQuery textbox.val('xxxx') not causing change to fire?

烈酒焚心 提交于 2019-11-27 19:36:17

That's the way it works. If you need the change of value to trigger the "change" event, you can explicitly do so by:

$('input#whatever').val('hi').change();

$('.change').change() will fire the event. Just changing the attributes doesn't fire the event.

According to DOM Level 2 Event Specification:

The change event occurs when a control loses the input focus and its value has been modified since gaining focus.

That means that change event is designed to fire on change by user interaction. Programmatical changes doesn't cause this event to be fired.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!