Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用javascript将类样式添加到编辑器文本_Javascript_Html_Css_Ckeditor - Fatal编程技术网

使用javascript将类样式添加到编辑器文本

使用javascript将类样式添加到编辑器文本,javascript,html,css,ckeditor,Javascript,Html,Css,Ckeditor,我正在构建一个自包含的网页,并使用CKEditor 4.6.2进行输入。目前,我的最后一个障碍是尝试将css类样式应用于通过javascript插入的文本。我的css在head标签中,没有什么特别的。我已经按照CKEditor的指示定义了一个样式集 并将其添加到编辑器中 CKEDITOR.replace('LogBook', { language: 'en', uiColor: '#9AB8F3', toolbar: [ ['Undo','Re

我正在构建一个自包含的网页,并使用CKEditor 4.6.2进行输入。目前,我的最后一个障碍是尝试将css类样式应用于通过javascript插入的文本。我的css在head标签中,没有什么特别的。我已经按照CKEditor的指示定义了一个样式集

并将其添加到编辑器中

CKEDITOR.replace('LogBook', {
      language: 'en',
      uiColor: '#9AB8F3',
      toolbar: [
        ['Undo','Redo','-'],
        ['Bold','Italic','Underline','Strike','-'],
        ['RemoveFormat','-'],
        ['NumberedList','BulletedList','-'],
        ['HorizontalRule'],
        '/',
        ['Styles','-','Source','-','About','Maximize'],
      ],
      removeButtons: 'Subscript,Superscript,Cut,Copy,Paste,Anchor,Scayt,PasteText,PasteFromWord,Image,SpecialChar,Link,Unlink,Table,Indent,Outdent,Blockquote,Format',
      removePlugins: 'wsc,scayt',
 stylesSet:'my_custom_styles',
 allowedContent: true
    })
但就我的一生而言,我不知道如何在编辑器中使用javascript将类应用于元素,就像这样

<p class="My Custom Block">Some text here</p>
这里有一些文本

我已经关闭了内容过滤,并有一个自定义函数插入上述代码,但段落元素没有得到样式化

我还尝试从样式表中直接应用样式,如:

<p class="redText">Some text here</p>

这里有一些文本

但是,段落元素也没有得到样式化


任何帮助都会很好,谢谢。

经过长时间的搜索,我终于找到了(由surtyaar在底部)向CKEditor元素添加类的方法

CKEDITOR.addCss( '.redText { border-bottom: 1px dotted red }' );
在声明CKEditor实例之前,需要调用它


来自CKEditor。

请提及您的CKEditor版本。另外,添加您从其文档中跟踪的链接。很抱歉…完成。这正是我一直在寻找的。非常感谢。
CKEDITOR.addCss( '.redText { border-bottom: 1px dotted red }' );