简体   繁体   English

CKEDITOR:获取最后删除的元素html值

[英]CKEDITOR:get last deleted element html value

I'm working with CKEditor for the past few months.But, now I'm facing issue 过去几个月我一直在与CKEditor合作。但是,现在我遇到了问题

for deletion in CKEditor. 在CKEditor中删除。

My Question is:: 我的问题是:

How do I get the lastly deleted element's HTML value in CKEditor. 如何在CKEditor中获取最后删除的元素的HTML值。

When I click the Delete button, I want to get what is the element will 当我单击“删除”按钮时,我想知道元素将是什么

be Deleted and get Deleted elements HTML Value. 被删除并获取Deleted元素的HTML值。

Anyone, please help me. 任何人,请帮助我。

you can attach listener when editor content is ready, and check for delete or backspace press and get the last deleted content, an example could be like:: 您可以在编辑器内容准备就绪时附加侦听器,并检查是否按Delete键或退格键并获取上次删除的内容,示例如下:

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"));

                }
            });
        }
    }
});

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

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