问题:在对div设置属性 contenteditable="true" 的时候,由于需要对输入的内容变化进行监听,由于在ie中使用 input、change、propertychange等事件进行监听的时候,无法监听到输入内容的变化,所以这里使用了MutationObserver对象来实现。
使用方式如下:
//ie下无法监听输入变化,使用下面的方法监听
// 设置observer的配置选项
var config = { attributes: true, childList: true, subtree: true,characterData:true };
// 当节点发生变化时的需要执行的函数
var callback = (mutationsList, observer) => {
for(var mutation of mutationsList) {
if (mutation.type == 'childList') {
this.changeTxt()
}
else if (mutation.type == 'attributes') {
this.changeTxt()
} else if(mutation.type == 'characterData'){
this.changeTxt()
}
}
};
// 创建一个observer示例与回调函数相关联
var observer = new MutationObserve