【php】ThinkPHP搭建百度Ueditor富文本编辑器

编程知识 行业动态 更新时间:2024-06-13 00:22:48

简介

UEditor是由百度web前端研发部开发所见即所得富文本web编辑器,具有轻量,可定制,注重用户体验等特点,开源基于MIT协议,允许自由使用和修改代码。


下载UEditor

官网下载:http://ueditor.baidu/website/download.html

将下载好的文件解压到thinkphp项目中,本文是解压到PUBLIC目录下并改文件夹名称为ueditor


第一步 引入javascript

在html中如入下面的js语句引入相关文件
<script type="text/javascript" charset="utf-8" src="__PUBLIC__/ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="__PUBLIC__/ueditor/ueditor.all.js"></script>


第二步 添加textare文本域并设置id值

<textarea  type="text"  name="content" id="EditorId" placeholder="请输入内容"></textarea>

第三步 初始化UEditor编辑器

在html代码中添加下面的代码初始化UEditor编译器
<script type="text/javascript" charset="utf-8">//初始化编辑器
     window.UEDITOR_HOME_URL = "__PUBLIC__/ueditor/";//配置路径设定为UEditor所放的位置
     window.οnlοad=function(){
        window.UEDITOR_CONFIG.initialFrameHeight=600;//编辑器的高度
        window.UEDITOR_CONFIG.initialFrameWidth=1200;//编辑器的宽度
        var editor = new UE.ui.Editor({
            imageUrl : '',
            fileUrl : '',
            imagePath : '',
            filePath : '',
            imageManagerUrl:'', //图片在线管理的处理地址
            imageManagerPath:'__ROOT__/'
        });
        editor.render("EditorId");//此处的EditorId与<textarea name="content" id="EditorId">的id值对应 </textarea>
    }
</script>

第四步 设置图片上传路径

UEditor编辑器的默认图片上传路径是根目录下/ueditor/php/upload/image/目录,没有这个目录会自动创建,如果要自定义图片上传路径,可以在ueditor/php/config.json文件中12行处修改。

最后贴上完整的html代码:
 <!DOCTYPE html>
 <html lang="en">
 <head>
 	<meta charset="UTF-8">
 	<title>Document</title>
 	<script type="text/javascript" charset="utf-8" src="__PUBLIC__/ueditor/ueditor.config.js"></script>
	<script type="text/javascript" charset="utf-8" src="__PUBLIC__/ueditor/ueditor.all.js"></script>
 </head>
 <body>

	 <form action="__URL__/receiver" method="post" accept-charset="utf-8">
		<textarea  type="text"  name="content" id="EditorId" placeholder="请输入内容"></textarea>
		<input type="submit" value="提交">
	 </form>
 	
 	<script type="text/javascript" charset="utf-8">//初始化编辑器
     window.UEDITOR_HOME_URL = "__PUBLIC__/ueditor/";//配置路径设定为UEditor所放的位置
     window.οnlοad=function(){
        window.UEDITOR_CONFIG.initialFrameHeight=600;//编辑器的高度
        window.UEDITOR_CONFIG.initialFrameWidth=1200;//编辑器的宽度
        var editor = new UE.ui.Editor({
            imageUrl : '',
            fileUrl : '',
            imagePath : '',
            filePath : '',
            imageManagerUrl:'', //图片在线管理的处理地址
            imageManagerPath:'__ROOT__/'
        });
        editor.render("EditorId");//此处的EditorId与<textarea name="content" id="EditorId">的id值对应 </textarea>
    }
	</script>
 </body>
 </html>

效果图



参考文档

http://blog.csdn/lshake/article/details/52554992
http://www.jb51/article/94848.htm

更多推荐

【php】ThinkPHP搭建百度Ueditor富文本编辑器

本文发布于:2023-04-03 07:22:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/df0a7a46635e1ffd75c783ab5848bd25.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:编辑器   文本   php   ThinkPHP   Ueditor

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!