您可以使用

MutationObserver来实现此目的.要跟踪从您的contenteditable元素中删除的任何类型的节点,请遵循以下示例

span

var observer = new MutationObserver(function(mutations) {

mutations.forEach(function(mutation) {

//console.log($(mutation.removedNodes)); // <

$(mutation.removedNodes).each(function(value, index) {

if(this.nodeType === 1) {

console.log(this) // your removed html node

}

});

});

});

var config = { attributes: true, childList: true, characterData: true };

observer.observe($('#myTextArea')[0], config);

Logo

Agent 垂直技术社区,欢迎活跃、内容共建。

更多推荐