2
有办法有一个js函数加载或每次当DOM被修改时调用该函数?我有一个html页面,我在这个页面上从动作按钮中展开另一个面板,这样dom被修改,我的js函数不再被调用:
有办法有一个js函数加载或每次当DOM被修改时调用该函数?我有一个html页面,我在这个页面上从动作按钮中展开另一个面板,这样dom被修改,我的js函数不再被调用:
代码
$("#a").bind("DOMSubtreeModified", function() {
if (window.PIE) {
$(this).each(function() {
PIE.attach(this);
});
}
alert("tree changed");
});
$("#add").click(function() {
$("#a").append("<span>hey there</span>");
});
HTML:
<div id="a"></div>
<button id="add">Add to Div</button>
工作fiddle
非常感谢..! – mcmwhfy
http://stackoverflow.com/questions/1091661/detect-element-content-changes-with-jquery http://stackoverflow.com/questions/2844565/is-there-a-jquery-dom-change-listener – bhb
不,但您可以创建一个自定义事件并在每次完成修改时触发它DOM。 –
以及如何做到这一点? – mcmwhfy