CKEDITOR:获取上次删除的元素 html 值



在过去的几个月里,我一直在与CKEditor合作。但是,现在我遇到了问题

用于在 CKEditor 中删除。

我的问题是::

如何在 CKEditor 中获取最后删除的元素的 HTML 值。

当我单击"删除"按钮时,我想获取元素将是什么

为"已删除

"并获取"已删除元素"HTML 值"。

任何人,请帮助我。

您可以在

编辑器内容准备就绪时附加侦听器,并检查删除或退格键并获取最后删除的内容,例如:

CKEDITOR.replace( 'your-editor', {
    ...,
    on: {
        contentDom: function () { //editor content ready
            var myEditor = this;
            //add listener
            this.editable().attachListener( editor, 'key', function( evt ) {
                //if delete or backspace pressed
                if ( ( evt.data.keyCode in { 8: 1, 46: 1 } ) ) {
                    //get the last element
                    var lastElement = myEditor.elementPath().lastElement,
                        lastElementName = lastElement.getName(),
                        lastElementNode = lastElement.$; //native DOM object
                        //see what properties the node has
                        console.log(lastElementNode);
                        //you can use getAttribute to fetch specific attr
                        //for example, for img element's src attribute
                        console.log(lastElementNode.getAttribute("src"));
                }
            });
        }
    }
});

最新更新