靈活的呼叫方式——JS程式碼呼叫:
- <script type="text/javascript" src="../../ckeditor/ckeditor.js"></script>
- <textarea cols="80" id="editor1" name="editor1" rows="10"><p>Ckeditor的初始化內容,作為textarea的value值. You are using <a href="http://www.kxss.net/">CKEditor</a>.</p></textarea>
- <script type="text/javascript">
- CKEDITOR.replace( 'editor1' );
- </script>
其實很簡單,包含Ckeditor的js檔案,生成textarea,用就是語句替換。js預計替換,可以進行更為詳細的配置,下文將做詳細說明。
二、Ckeditor工具欄自定義設定
1.在Ckeditor根目錄的config.js中設定:
- config.toolbar = 'Full';
- config.toolbar_Full =
- [
- ['Source','-','Save','NewPage','Preview','-','Templates'],
- ['Cut','Copy','Paste','PasteText','PasteFromWord','-','Print', 'SpellChecker', 'Scayt'],
- ['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'],
- ['Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField'],
- '/',
- ['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
- ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote'],
- ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
- ['Link','Unlink','Anchor'],
- ['Image','Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak'],
- '/',
- ['Styles','Format','Font','FontSize'],
- ['TextColor','BGColor'],
- ['Maximize', 'ShowBlocks','-','About']
- ];
- config.toolbar_Basic =
- [
- ['Bold', 'Italic', '-', 'NumberedList', 'BulletedList', '-', 'Link', 'Unlink','-','About']
- ];
上述程式碼中第一行,即為設定預設工具欄的,可以改寫為:
- config.toolbar = 'Basic';
2.在用js程式碼呼叫Ckeditor時設定:
- CKEDITOR.replace( 'editor1',
- {
- toolbar :
- [
- ['Styles', 'Format'],
- ['Bold', 'Italic', '-', 'NumberedList', 'BulletedList', '-', 'Link', '-', 'About']
- ]
- });
3.以上兩種方法的綜合:
在Ckeditor根目錄下的config.js檔案中設定好多組toolbar,如方法1示
例程式碼去掉第一行;呼叫Ckeditor時的程式碼如下:
- CKEDITOR.replace( 'editor1',
- {
- toolbar : 'Full'
- });
- CKEDITOR.replace( 'editor2',
- {
- toolbar : 'Basic'
- });
三、Ckeditor語言、字型及皮膚樣式自定義
Ckeditor支援多國語言,並提供三種皮膚樣式:kama、office2003和v2,可以在Ckeditor根目錄下的config.js檔案中進行設定:
- config.language = 'zh-cn' ;
- config.skin = 'office2003';
也可以在js呼叫Ckeditor時設定:
- CKEDITOR.replace( 'editor1',
- {
- toolbar : 'Full',
- language : 'zh-cn',
- skin : 'office2003'
- });
- CKEDITOR.replace( 'editor2',
- {
- toolbar : 'Basic',
- language : 'zh-cn';
- skin : 'kama'
- });
四、Ckeditor新增中文字型
1.在Ckeditor根目錄下的config.js檔案中新增:
- config.font_names = '宋體;黑體;隸書;楷體_GB2312;Arial;Comic Sans MS';
2.在用js程式碼呼叫Ckeditor時新增:
- CKEDITOR.replace( 'editor1',
- {
- toolbar : 'Full',
- language : 'zh-cn',
- skin : 'office2003',
- config.font_names : '宋體;黑體;隸書;楷體_GB2312;Arial;Comic Sans MS'
- });