使用百度的富文本编辑器UEditor遇到的问题总结
1、下载地址:http://ueditor.baidu.com/website/download.html(我下载的是.net版本)
下载后要先看一下ueditor.config.js和 net/config.json的文件,里面是关于图片上传和其他方法的一些路径配置


2、显示编辑页面(一定要看使用文档:http://fex.baidu.com/ueditor/#server-deploy)
- 引入所需的js文件

- 初始化编辑器 html代码:
<div class="form-group has-warning">
<textarea class="A4page" id="myEditor" name="NewsContent"></textarea>
</div>jquery代码:
var ue = UE.getEditor('myEditor', {
toolbars: [
['fullscreen', 'source', '|', 'undo', 'redo', '|',
'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc', '|',
'rowspacingtop', 'rowspacingbottom', 'lineheight', '|',
'customstyle', 'paragraph', 'fontfamily', 'fontsize', '|',
'directionalityltr', 'directionalityrtl', 'indent', '|',
'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|', 'touppercase', 'tolowercase', '|',
'link', 'unlink', 'anchor', '|', 'imagenone', 'imageleft', 'imageright', 'imagecenter', '|',
'simpleupload', 'insertimage', 'emotion', 'scrawl', 'insertframe', 'insertcode', 'pagebreak', 'template', 'background', '|',
'horizontal', 'date', 'time', 'spechars', 'snapscreen', 'wordimage', '|',
'inserttable', 'deletetable', 'insertparagraphbeforetable', 'insertrow', 'deleterow', 'insertcol', 'deletecol', 'mergecells', 'mergeright', 'mergedown', 'splittocells', 'splittorows', 'splittocols', 'charts', '|',
'print', 'preview', 'searchreplace', 'help', 'drafts']
],
allHtmlEnabled: false,//提交到后台的数据是否包含整个html字符串
autoHeightEnabled: false,
autoFloatEnabled: true,
allowDivTransToP: false//阻止div标签自动转换为p标签
});说明:修改配置项的方法: 1. 方法一:修改 ueditor.config.js 里面的 toolbars 2. 方法二:实例化编辑器的时候传入 toolbars 参数(详情参考:http://fex.baidu.com/ueditor/#start-toolbar)
- 前端配置基本上配置好了,下面是后端配置(如果后端配置不好,上传图片功能将无法使用。网址:http://fex.baidu.com/ueditor/#server-net)我配置了好久才配置好的,按照文档上说的做就行了
- 当你的编辑器可以使用的时候,获取编辑器里的内容(网址:http://fex.baidu.com/ueditor/#api-common)
//实例化编辑器到id为 container 的 dom 容器上:
var ue = UE.getEditor('container');
//设置编辑器内容:
ue.ready(function() {
ue.setContent('<p>hello!</p>');
});
//追加编辑器内容:
ue.ready(function() {
ue.setContent('<p>new text</p>', true);
});
//获取编辑器html内容:
ue.ready(function() {
var html = ue.getContent();
});
//获取纯文本内容:
ue.getContentTxt();
//获取保留格式的文本内容:
ue.getPlainTxt();
//获取纯文本内容:
ue.getContentTxt();
//判断编辑器是否有内容:
ue.hasContents();
//让编辑器获得焦点:
ue.focus();
//让编辑器获得焦点
ue.blur();
//判断编辑器是否获得焦点:
ue.isFocus();
//设置当前编辑区域不可编辑:
ue.setDisabled();
//设置当前编辑区域可以编辑:
ue.setEnabled();
//隐藏编辑器:
ue.setHide();
//显示编辑器:
ue.setShow();
//获得当前选中的文本:
ue.selection.getText();
//常用命令:
//在当前光标位置插入html内容
ue.execCommand('inserthtml', '<span>hello!</span>');
//设置当前选区文本格式:
ue.execCommand('bold'); //加粗
ue.execCommand('italic'); //加斜线
ue.execCommand('subscript'); //设置上标
ue.execCommand('supscript'); //设置下标
ue.execCommand('forecolor', '#FF0000'); //设置字体颜色
ue.execCommand('backcolor', '#0000FF'); //设置字体背景颜色
//回退编辑器内容:
ue.execCommand('undo');
//撤销回退编辑器内容:
ue.execCommand('redo');
//切换源码和可视化编辑模式:
ue.execCommand('source');
//选中所有内容:
ue.execCommand('selectall');
//清空内容:
ue.execCommand('cleardoc');
//读取草稿箱
ue.execCommand('drafts');
//清空草稿箱
ue.execCommand('clearlocaldata');- 输入的数据是这样的:

获取到的数据是这样的:<p><img src="http://img.baidu.com/hi/jx2/j_0015.gif"/><img src="/assets/utf8-net/net/upload/image/20160427/6359737678078530983400002.jpg" title="QQ截图20160427144629.jpg" alt="QQ截图20160427144629.jpg"/>防火防盗发货的发货</p>
- 将数据存到数据库中了,那么怎么让数据原样显示到编辑器里呢?(这个问题我试了一天,开始我以为是这个函数uParse,但是我试了好多路径都不管用,如果谁用这个方法实现了,一定要告诉我一声哦,先qqq了)
- 后台获取数据:
public ActionResult GetDetails(string NewsId)
{
int id = Int32.Parse(NewsId);
NewsInfo news = db.NewsInfoes.Find(id);
ViewData["news"] = news;
return View();
}前台html代码:
<div class="col-sm-6">
<div class="panel">
<div class="panel-body">
<div class="form-group has-success">
<label class="control-label" for="NewsName">新闻标题:</label>
<input type="text" class="form-control" id="NewsName" name="NewsName" placeholder="新闻标题" style="width:600px" value="@(((NewsInfo)ViewData["news"]).NewsName)" />
</div>
<div class="form-group has-warning">
<textarea class="A4page" id="myEditor" name="NewsContent">@(((NewsInfo)ViewData["news"]).NewsContent)</textarea>
</div>
</div>
</div>
</div>jquery代码:
function load() {
var ue = UE.getEditor('myEditor', {
toolbars: [
['fullscreen', 'source', '|', 'undo', 'redo', '|',
'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc', '|',
'rowspacingtop', 'rowspacingbottom', 'lineheight', '|',
'customstyle', 'paragraph', 'fontfamily', 'fontsize', '|',
'directionalityltr', 'directionalityrtl', 'indent', '|',
'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|', 'touppercase', 'tolowercase', '|',
'link', 'unlink', 'anchor', '|', 'imagenone', 'imageleft', 'imageright', 'imagecenter', '|',
'simpleupload', 'insertimage', 'emotion', 'scrawl', 'insertframe', 'insertcode', 'pagebreak', 'template', 'background', '|',
'horizontal', 'date', 'time', 'spechars', 'snapscreen', 'wordimage', '|',
'inserttable', 'deletetable', 'insertparagraphbeforetable', 'insertrow', 'deleterow', 'insertcol', 'deletecol', 'mergecells', 'mergeright', 'mergedown', 'splittocells', 'splittorows', 'splittocols', 'charts', '|',
'print', 'preview', 'searchreplace', 'help', 'drafts']
],
autoHeightEnabled: false,
autoFloatEnabled: true,
allowDivTransToP: false//阻止div标签自动转换为p标签
});
} $(function () {
load();
});然后就可以了,O(∩_∩)O哈哈~
- 我的流程:先添加数据

- 在新闻列表里点击新闻标题,传递新闻id获取新闻详细内容

- 最后将数据展示到新闻修改页面的编辑器上

使用百度的富文本编辑器UEditor遇到的问题总结的更多相关文章
- 百度Web富文本编辑器ueditor在ASP.NET MVC3项目中的使用说明
====================================================================== [百度Web富文本编辑器ueditor在ASP.NET M ...
- 百度开源富文本编辑器 UEditor配置:图片上传和文件上传独立使用方法
使用UEditor编辑器自带的插件实现图片上传和文件上传功能,这里通过配置UEditor单独使用其内置的第三方插件swfupload来实现图片和文件的上传,通过对UEditor配置轻松实现图片批量上传 ...
- 百度的富文本编辑器UEditor批量添加图片自动加上宽度和高度的属性
若是没有对编辑器做任何配置直接添加图片的话,显示的html内容如下图所示:它会显示出原图片尺寸 所以必须要对图片的初始显示尺寸做控制:ueditor文件中找到image.js文件 在image.js中 ...
- 百度的富文本编辑器UEDITOR
还是百度的ueditor 比较好用,文件导入后,基本不用配置就可以直接使用图片,文件上传等功能. CKeditor要注意的地方太多了 .但是相对ckeditor 样式比较好看.
- 百度富文本编辑器UEditor安装配置全过程
网站开发时富文本编辑器是必不可少的,他可以让用户自行编辑内容的样式然后上传到后台!下面我们来介绍如何安装使用百度富文本编辑器 一.下载并且设置百度富文本编辑器的样式 你可以去百度UEditor ...
- 百度富文本编辑器ueditor使用总结
最近做的项目用到了ueditor这个东东,但是他的一些配置文档对初次使用者来说很难以理解,故作此总结 相关详细操作链接地址: http://blog.csdn.net/wusuopubupt/arti ...
- 百度富文本编辑器ueditor使用启示
百度富文本编辑器ueditor使用启示 一.总结 一句话总结:使用工具,多去看官方demo,非常详细. 二.百度富文本编辑器ueditor使用启示 官方完整demo 官方完整demo对应的源代码 &l ...
- springboot+layui 整合百度富文本编辑器ueditor入门使用教程(踩过的坑)
springboot+layui 整合百度富文本编辑器ueditor入门使用教程(踩过的坑) 写在前面: 富文本编辑器,Multi-function Text Editor, 简称 MTE, 是一 ...
- thinkphp5.1中适配百度富文本编辑器ueditor
百度富文本编辑器ueditor虽然很老,但是功能齐全,我近期需要能批量粘贴图片的功能,但是找不到,很无奈.然后现在就分享一下如何把ueditor适配到thinkphp5.1,有知道如何批量上传图片的艾 ...
随机推荐
- 【sqli-labs】Less7
Less-7: 输出文件 sql导出文件语句 select * from table_test into outfile 'test.txt' 既然名字是输出文件,那肯定是和文件有关系. 首先,确保s ...
- 性能测试四十八:Jenkins+Ant+Jmeter系统部署
工作步骤: 1.开发提交代码SVN/Git 2.代码编译.打war包 3.上传war包到服务器 4.重启web服务器 5.开始测试/自动化测试 6.发测试结果 Jenkins工作: 1.开发提交代码G ...
- Android定位元素与操作
一.常用识别元素的工具 uiautomator:Android SDK自带的一个工具,在tools目录下 monitor:Android SDK自带的一个工具,在tools目录下 Appium Ins ...
- docker文件复制到centos/linux/ubantun环境下
1.有些时候我们需要将容器里面的文件,弄到系统里面来分析,像报错log等 格式:docker cp 容器名:文件在容器里面的路径 要拷贝到宿主机的对应路径 2.有些情况下,我们需要将文 ...
- windows客户端走代理上网
前提:在大型网络中,由于众多服务器及安全性考虑,内网服务器是不能上外网的,但是为了满足某些服务的需要,一定会搭建代理服务器的. 以下是windows客户端走代理服务器的操作: 两下确定就可 ...
- Android Studio 修改包名最便捷做法
Android Studio,咱们开发安卓的利器,自推出就受到移动开发者的追捧,但一路走来,大家谈到他,充满了兴奋之情之余,也略显羞涩.随版本自推出以来,不断完善BUG,但咱们还是深深地踩了进去,说多 ...
- TFS: 解决The build agent error - the session for this agent already exists
来源:http://ericphan.net/blog/2016/6/10/solving-the-tfs-build-agent-error-the-session-for-this-agent-a ...
- WPF编程之找不到资源mainWindow.xaml
原文: WPF编程之找不到资源“window1.xaml”之谜 因为将启动窗口移动到了一个新建的文件夹中,启动调试时报找不到资源mainWindow.xaml,原来是App.xaml里面设置的启动窗口 ...
- python---自己来打通节点,链表,栈,应用
但,, 没有调试通过. 思路是对的,立此存照. 关键就是用链表完全实现列表的功能, 替换了就应该OK的. # coding = utf-8 # 节点初始化 class Node: def __init ...
- 【BZOJ4764】弹飞大爷
题解: 这个应该还是比较简单的 首先比较容易想到用lct来维护 我们可以建立一个特殊点 然后我们要处理环 其实只要判断它和不和这个特殊点联通就行了 那么当它不是环了我们怎么还原呢 只要对每个在根节点记 ...