3

好吧,这看起来很简单,我想<strike>在选择之前添加一个并在选择之后添加/by User</strike>..

这是我到目前为止得到的:

CKEDITOR.plugins.add('test',
{
    init: function (editor) {
        editor.addCommand('inserttest',
            {
                exec: function (editor) {
                    var selection = editor.getSelection();
                    if (!selection) {
                        return;
                    }
                    var text = selection.getSelectedText();

                    editor.insertHtml('<strike>' + text + ' /By User </strike>');
                }
            });

        editor.ui.addButton('test',
            {
                label: 'Insert test',
                command: 'inserttest',
                icon: this.path + 'images/test.png'
            });
    }
});

这有点工作,但它有一些怪癖它删除了所有 html 并且它也不能验证我们是否已经在罢工中......

那么我将如何在不丢失 html 的情况下做到这一点?并验证我已经不在罢工标签内?

我试图分析插件的源代码,但发现它至少可以说令人困惑......

注意我使用 asp.net 控制女巫似乎使用 CKEditor 的 3.6.4 版本。

4

1 回答 1

1

我不知道您是否已经找到答案并且问题是真实的,但希望这个答案对将来偶然发现此错误的人有所帮助。

而不是使用editor.insertHtml为您的罢工代码创建元素并仅将元素添加到编辑器。

selection.getSelectedText().setData(''); // cleans the selection
var strikeElement= editor.document.createElement('strike');
strikeElement.setText(text + ' /By User');
editor.insertElement(strikeElement);
于 2015-07-02T09:25:30.307 回答