【发布时间】:2018-10-26 23:19:57
【问题描述】:
拜托,我真的不是程序员。
当孩子附加到 div 时,我需要拦截。
喜欢这个例子(没有超时):
$(document).ready(function(){
setTimeout(function(){
$('#holder').append('<div id="device">Test</div>');}, 2000);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<body>
<div id="holder">
<!––child dynamicly inserted-->
</div>
</body>
我使用了 mutationobserver 但接缝似乎已弃用...我看到了 proxy() 但我不知道如何使用它...
我的变异观察者代码:
MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
var observer = new MutationObserver(function(mutations, observer) {
mutations.forEach(function(mutation) {
if ($('#main-view div.row').next().length != 0 ){
DelRow();
};
$('#main-view div.row.divider .span4').toggleClass('span4 tile');
});
});
$( document ).ready(function() {
if (!isMobile){
observer.observe(targetedNode, {
childList: true,
subtree: true
});
但不要在移动设备上工作..
【问题讨论】:
-
你用
Mutation Observer做了什么? -
Mutation Observer 似乎仍然可用:developer.mozilla.org/en-US/docs/Web/API/MutationObserver
-
我用变异观察者MutationObserver = window.MutationObserver || window.WebKitMutationObserver; var observer = new MutationObserver(function(mutations, observer) { mutation.forEach(function(mutation) { $('#main-view').contents().removeClass('container').toggleClass('container-fluid' ); $('#main-view div.row.divider .span4').toggleClass('span4 tile'); }); });不推荐使用要被观察者()的接缝。但我真的不能说这是否是同一件事......developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…
标签: javascript jquery dom mutation