简体   繁体   English

为什么mutationObserver不起作用?

[英]Why isn't the mutationObserver working?

From my understanding mutationObserver is used similarly to how eventListeners are. 据我了解,mutationObserver的用法与eventListeners相似。 I'm trying to use it in place of an event listener, so I can have a div react to changes. 我试图用它代替事件监听器,所以我可以让div对更改做出反应。 My problem is nothing is being printed to the console when I type something in the div. 我的问题是当我在div中键入内容时,什么都没有打印到控制台。 Something should be printed to the console, but it's not and I'm not sure why. 应该在控制台上打印一些东西,但是不是,我不确定为什么。 What am I doing wrong here? 我在这里做错了什么?

    <div contenteditable="true" class="input"></div>
    <div class="display"></div>


        let input= document.getElementsByClassName("input")[0];
        let displat= document.getElementsByClassName("dispaly")[0];

        let config={attributes:true, childlist:true, characterData:true};

        let observer= new MutationObserver(function(mutations){
            mutations.forEach(function(mutation){
            console.log(mutation.type);
             });
          }); 
    observer.observe(input,config);       

您编写了“ childlist”,它必须是“ childList”,并带有大写的L。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM