ckeditor 介绍
ckeditor宣称是最好的web文本编辑器:
1.它功能强大,配置简单。
2.它是基于插件配置的,也就是说,你可以根据自己项目要求剔除掉一些特性。
目前,它最新版本是4.2.下面是一些有用的链接:
官网:http://ckeditor.com/
文档:http://docs.ckeditor.com/
示例
在看见最终效果请,需要安装ckeditor,安装是很简单的:
以java项目为例,可以将你下载的文件解压到webRoot根目录下,ckeditor是缺省目录。
本文打算用两个简单的例子,介绍它的用法。
使用默认配置
框架式编辑是使用CKeditor最常用的的方式,它通常的表现方式是在页面中指定位置放置工具栏和编辑区。
代码如下:
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<script type="text/javascript" src="ckeditor/ckeditor.js"></script>
<link rel="stylesheet" href="ckeditor/samples/contents.css"
type="text/css"></link>
</head>
<body>
<textarea name="myEditor"></textarea>
<script>
window.οnlοad=function(){
CKEDITOR.replace('myEditor');
}
</script>
</body>
</html>
效果如下:
使用你喜欢的配置
很多时候,不同的项目需要我们的编辑器有不同的toolbar,我们可以修改config.js文件,加入以下代码:
config.toolbar =[['Source','Styles', 'Format','FontSize','Font'],
['TextColor', '-' ,'Bold', 'Italic', '-', 'NumberedList', 'BulletedList', '-', 'Link','Unlink','-','Cut','Copy','Paste','-','Image','Flash','Smiley','Maximize']
];
效果如下: