像这样的功能应该可以帮助您
document.addEventListener("DOMNodeInserted", function(event){
var element = event.target;
if (element.tagName == 'li') {
alert("li added");
}
});
检查突变事件
小提琴演示
HTML
<div id="container" style="background-color:#e0d0a0; width:300px; height:100px;"></div>
<button onclick="AddLiToContainer ();">Add a li node to the container!</button>
JAVASCRIPT
function AddLiToContainer() {
var newLi = document.createElement("li");
var textNode = document.createTextNode("Hello World");
newLi.appendChild(textNode);
if (newLi.addEventListener) {
newLi.addEventListener('DOMNodeInserted', OnNodeInserted, false);
}
var container = document.getElementById("container");
container.appendChild(newLi);
}
function OnNodeInserted(event) {
var Li = event.target;
alert("The text node '" + Li.innerHTML + "' has been added to an element.");
}