簡體   English   中英

CKEDITOR:獲取最后刪除的元素html值

[英]CKEDITOR:get last deleted element html value

過去幾個月我一直在與CKEditor合作。但是,現在我遇到了問題

在CKEditor中刪除。

我的問題是:

如何在CKEditor中獲取最后刪除的元素的HTML值。

當我單擊“刪除”按鈕時,我想知道元素將是什么

被刪除並獲取Deleted元素的HTML值。

任何人,請幫助我。

您可以在編輯器內容准備就緒時附加偵聽器,並檢查是否按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