How do you get a mutation observer to detect a value change of a textarea?

a 夏天 提交于 2019-11-28 12:12:05

The mutation observers listen for changes of the DOM. The current state of form elements, however, is not reflected by the DOM.

For example, create an input element input without setting the value attribute. When text is being entered into the input field, input.value reflects this text. On the other hand, input.getAttribute('value') still returns null.

Therefore, the mutation observers can't observe this change in the form field's status.

(Object.observe of the proposed ECMAScript 6th edition also doesn't help. Although one can listen on changes of host objects in recent versions of Chrome, changes of host object properties like value of input above are not being observed.)

Chao Zhang

See this link Textarea onchange detection. You will need to write onkeyup and onchange function.

By the way, the answer above will not work for an input method. My solution is setInterval to detect if the text has changed every 50 ms.

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