2013-08-05 78 views

回答

2

来吧用下面的代码:

// Your custom style. 
var myStyle = new CKEDITOR.style({ 
    element: 'span', 
    attributes: { 
     'data-foo': 'bar', 
     'class': 'myClass' 
    }, 
    styles: { 
     color: 'red' 
    } 
}); 

CKEDITOR.replace('editor1', { 
    on: { 
     // Register command and button along with other plugins. 
     pluginsLoaded: function() { 
      var editor = this; 

      // Registers a command that applies the style. 
      // Note: it automatically adds Advanced Content Filter rules. 
      this.addCommand('myStyle', new CKEDITOR.styleCommand(myStyle)); 

      // Add toolbar button for this command. 
      this.ui.addButton && this.ui.addButton('myStyleButton', { 
       label: 'My style', 
       command: 'myStyle', 
       toolbar: 'insert,10' 
       // You may want to set some icon here. 
       // icon: 'someIcon' 
      }); 
     } 
    } 
}); 
+0

谢谢!你能确认这个代码应该进入哪个文件吗?它应该在styles.js中还是我需要编辑多个文件? – Jon

+0

这取决于你如何定义你的配置。你应该把这个'pluginsLoaded'监听器放在那里,并确保'myStyle'在一个范围内。 – oleq

+0

我已经放入一个单独的脚本,在页面加载后运行,它似乎工作得很好!一件小事:你如何定义一个新的工具栏?上面的例子将新按钮添加到“插入”工具栏。我想把我所有的自定义按钮放在他们自己的独立工具栏上。谢谢! – Jon