单击按钮插入数据到 ckeditor

Insert data on a button click to ckeditor

我必须使用 ckeditor 使文本区域可编辑。在编辑器之后放置一个按钮。如果单击该按钮,我需要向编辑器添加 html 代码。 加载CK Editor的代码是:

CKEDITOR.replace('mail_content');
CKEDITOR.config.toolbar = [
                ['Styles','Format','Font','FontSize'],
                // '/',
                ['Bold','Italic','Underline','StrikeThrough','-','Undo','Redo','-','Cut','Copy','Paste','Find','Replace','-','Outdent','Indent','-','Print'],
                // '/',
                ['NumberedList','BulletedList','-','JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
                ['Flash','TextColor','BGColor']
            ] ;

按钮是

<button name="edit" id="edit" >edit</button>

我不完全明白你需要什么,但如果你需要例子,看看这个

<textarea name="mail_content" id="mail_content" rows="10" cols="80">
  This is a test
</textarea>
<button name="edit" id="edit" >edit</button>
<script>
$('#edit').click(function(){
  CKEDITOR.editorConfig = function (config) {
      config.language = 'es';
      config.uiColor = '#F7B42C';
      config.height = 300;
      config.toolbarCanCollapse = true;
            config.toolbar = [
                ['Styles','Format','Font','FontSize'],
                // '/',
                ['Bold','Italic','Underline','StrikeThrough','-','Undo','Redo','-','Cut','Copy','Paste','Find','Replace','-','Outdent','Indent','-','Print'],
                // '/',
                ['NumberedList','BulletedList','-','JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
                ['Flash','TextColor','BGColor']
            ] ;

  };
  CKEDITOR.replace('mail_content');
});
</script>

https://jsfiddle.net/reoh7j74/527

使用insertHtml:

CKEDITOR.instances.mail_content.insertHtml('<p>dsfds</p>');