如何在HTML中触发onChange事件,即使在js中内容发生了变化?
我知道 HTML onChange
事件仅在元素模糊时才会触发。
但是有没有办法在文本框的内容发生变化时运行脚本呢?即使在Javascript中改变了?
我的表单中有一个文本框来选择日期。我还有一个带有日历的按钮来选择日期。该日历写在文本框中,我想在日期更改时执行一些操作。
我无法更改日历的 Javascript。
我还希望与所有主要浏览器兼容(IE7-9、Firefox、Chrome、Safari、Opera...)。
I know the HTML onChange
event is triggered only when the element is blurred.
But is there a way to run a script when the content of a textbox changes? Even if it is changed in Javascript?
I have a textbox in my form to select a date. I also have a button with a calendar to pick a date. This calendar writes in the textbox and I want to do something when the date changes.
I cannot change the Javascript of the calendar.
I also want compatibility with all major browsers (IE7-9, Firefox, Chrome, Safari, Opera, ...).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您正在寻找突变事件(例如DomAttrModified)。
请参阅使用 jQuery 检测元素内容更改(如果这对初学者有帮助)。
You're looking for mutation events (eg. DomAttrModified).
See Detect element content changes with jQuery if that would help you as a starter.
我找到了我的问题的答案,可能不是更好的答案,但仍然有效。它使用 JavaScript 定时器。
我知道这不是世界上更好的代码,但它适用于所有主要浏览器。
I found an answer to my question wich is maybe not the better one, but still works. It uses javascript timers.
I know this is not the better code in the world, but it works for every major browsers.