首页 > 解决方案 > 如何从ckeditor中删除特定按钮

问题描述

我在两个 textarea 上使用 ckeditor,但问题是我需要有限的选项来显示(B,IU)项目符号格式,我按照一个链接并在 config.js 中进行了更改,但它反映了所有 ckediotr,但我希望更改应该反映该文本区域的特定 ckediotr。

我关注的链接:

如何从 CKeditor 4 中删除按钮

1) 我只需要 B,I,U 所以我必须在 js ile 中提到

2)以上bultes风格只需要一个ckeditor

从 ckeditor 的 config.js 文件中删除按钮/项目符号。

CKEDITOR.editorConfig = function (config) {
config.removePlugins = 'save,newpage,flash,about,iframe,language'; 
//The options which remove all styles except (B,I,U)
};



<textarea class="form-control editor_cls" id="htapply" rows="5" required></textarea>

 <textarea class="form-control editor_cls"  id="htapply" rows="5" required></textarea>

在所有 textarea 上应用 ckeditor 的脚本

<script type="text/javascript">
$('.editor_cls').each(function() { //alert();
  var editor_id = $(this).attr('id');
  CKEDITOR.replace( editor_id, {
      height: 100
    });
});
</script>

标签: javascriptjqueryckeditor

解决方案


首先,你的文本区域应该有不同的 id,你不应该在同一个页面中有两次相同的 id。如果你给他们不同的ID,你将能够轻松地区分它们:

<textarea class="form-control editor_cls" id="htapply" rows="5" required></textarea>

<textarea class="form-control editor_cls"  id="htapply2" rows="5" required></textarea>

然后在您的 JS 代码中,您可以:

<script type="text/javascript">
$('.editor_cls').each(function() { //alert();
  var editor_id = $(this).attr('id');
  if (editor_id === 'htapply2') {
    // add B, I, U to this editor
    CKEDITOR.replace(editor_id, {
      height: 100,
      plugins: 'bold,italic,underline',
      removePlugins: 'save,newpage,flash,about,iframe,language'
    });
  } else {
    CKEDITOR.replace(editor_id, {
      height: 100,
      removePlugins: 'save,newpage,flash,about,iframe,language'
    });
  }
});
</script>

推荐阅读