<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>ueditor demo</title>
</head>
<body>
<!-- 加载编辑器的容器 -->
<script id="container" name="content" type="text/plain">
这里写你的初始化内容
</script>
<!-- 配置文件 -->
<script type="text/javascript" src="ueditor.config.js"></script>
<!-- 编辑器源码文件 -->
<script type="text/javascript" src="ueditor.all.js"></script>
<!-- 实例化编辑器 -->
<script type="text/javascript">
var ue = UE.getEditor('container')
</script>
</body>
</html>
src要写你放的地址
编辑器有很多可自定义的参数项,在实例化的时候可以传入给编辑器:
var ue = UE.getEditor('container', {autoHeight: false
})
配置项也可以通过 ueditor.config.js 文件修改,具体的配置方法请看前端配置项说明
通 getContent 和 setContent 方法可以设置和读取编辑器的内容
var ue = UE.getContent()//对编辑器的操作最好在编辑器ready之后再做
ue.ready(function() {
//设置编辑器的内容
ue.setContent('hello')
//获取html内容,返回: <p>hello</p>
var html = ue.getContent()
//获取纯文本内容,返回: hello
var txt = ue.getContentTxt()
})
在editor_config.js文件中有个textarea的配置项,默认是editorValue,在servlet中可以通过request对象合这个editorValue来获取编辑器中的内容。具体代码是:
request.getParameter("editorValue")
步骤如下:
一、官网上下载完整源码包,解压到任意目录
_examples:编辑器完整版的示例页面
_demos:编辑器的各种使用案例
dialogs:弹出对话框对应的资源和JS文件
themes:样式图片和样式文件
third-party:第三方插件
editor_all.js:_src目录下所有文件的打包文件
editor_all_min.js:editor_all.js文件的压缩版,建议在正式部署时才采用
editor_config.js:编辑器的配置文件,建议和编辑器实例化页面置于同一目录
二、部署UEditor到实际项目(UETest)中的步骤:
第一步:在项目的任一文件夹中建立一个用于存放UEditor相关资源和文件的目录,此处在项目根目录下建立,起名为ueditor。
第二步:拷贝源码包中的dialogs、themes、third-party、editor_all.js和editor_config.js到ueditor文夹中。
第三步:为简单起见,此处将以根目录下的index.jsp页面作为编辑器的实例化页面,用来展示UEditor的完整版效果。在index.jsp文件中,首先导入编辑器需要的三个入口文件,示例代码如下:
[html] view plaincopy
<meta http-equiv="Content-Type" content="text/htmlcharset=UTF-8">
<title>编辑器完整版实例</title>
<script type="text/javascript" src="ueditor/editor_config.js"></script>
<script type="text/javascript" src="ueditor/editor_all.js"></script>
<link rel="stylesheet" href="ueditor/themes/default/ueditor.css">
第四步:然后在index.php文件中创建编辑器实例及其DOM容器。具体代码示例如下:
[html] view plaincopy
<div id="myEditor"></div>
<script language="javascript" type="text/javascript">
var option = {
initialContent : '',//初始化编辑器的内容
minFrameHeight : 400,//设置高度
textarea : 'content'//设置提交时编辑器内容的名字,之前我们用的名字是默认的editorValue
}
var editor = new baidu.editor.ui.Editor(option)
editor.render("myEditor")
</script>
最后一步: 在/UETest/ueditor/ editor_config.js中查找URL变量配置编辑器在你项目中的路径。
[html] view plaincopy
//强烈推荐以这种方式进行绝对路径配置
URL=window.UEDITOR_HOME_URL||"/UETest/ueditor/"
至此,一个完整的编辑器实例就已经部署了!在浏览器中输入http://localhost:8080/UETest 运行下。