如何拦截javascript中的innerHTML变化? [英] how to intercept innerHTML changes in javascript?
本文介绍了如何拦截javascript中的innerHTML变化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要拦截网页中单元格内容的任何更改。
I need to intercept any changes in the content of a cell inside my webpage.
以下代码显示addEventListener不起作用。
The following code shows me that addEventListener does not work.
function modifyText() {
alert("!");
}
var el=document.getElementById("mycell");
el.innerHTML="a"
el.addEventListener("change", modifyText, false);
// After next instruction I expect an alert message but it does not appear...
el.innerHTML="Z";
代码只是一个玩具示例。在我的实际情况中,页面中的更改(因此也在单元格中)是由我无法控制的webapp进行的。
The code is just a toy example. In my real case the changes in the page (and therefore in the cell, too) are made by a webapp that I have NO control over.
推荐答案
您不能以这种方式收听DOM元素更改
。 更改
事件主要用于输入
s
You can't listen to a DOM element change
that way. change
event is mostly for input
s
有其他一些新的DOM 3活动可以帮助你。
There is some other new DOM 3 events that would help you on this.
这里有一些:
这篇关于如何拦截javascript中的innerHTML变化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文