您的位置:首页 > 其它

ckEditor使用方法

2011-07-31 21:33 399 查看


原帖地址

灵活的调用方式——JS代码调用:

<script type="text/javascript" src="../../ckeditor/ckeditor.js"></script> <!--此行为导入ckeditor.js文件,要注意目录是否正确。-->

<textarea cols="80" id="editor1" name="editor1" rows="10"></textarea>

<script type="text/javascript"> CKEDITOR.replace( 'editor1' ); <!--此行就是用ckeditor替换文本域textarea 这里editor1可以是文本域的id或者name--></script>


其实很简单,包含Ckeditor的js文件,生成textarea,然后用语句替换。js替换,可以进行更为详细的配置,下文将做详细说明。

二、Ckeditor工具栏自定义设置

在ckeditor目录下,有个Config.js

未配置的内容如下:

CKEDITOR.editorConfig = function( config ){// Define changes to default configuration here. For example:// config.language = 'fr';// config.uiColor = '#AADC6E';

//可以在此处进行配置,配置后调用后就能呈现相应的显示效果,详细内容如下。};

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 配置文件Config.js的一些具体配置信息

三、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'
});
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: