Programmatically manipulating DOM element value doesn't fire onchange event

后端 未结 2 1837
温柔的废话
温柔的废话 2021-01-28 11:56

I\'ve got a hidden form field, and when a button gets pressed the value of the hidden field is changed. Now, I\'ve added an observer to the hidden field, listening for changes t

2条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-28 12:27

    I don't think input elements that are hidden respond to that event.

    I don't know prototype, but I think the events being triggered is entirely up to the browser.

    Here is an example with jQuery on JSbin. Notice that changing the text yourself fires the event, however the next part of code that changes the value via script does not fire it.

提交回复
热议问题