百度编辑器UEditor与UEditor 公式插件完整Demo

时间:2022-09-20 17:31:06

1、下载UEditor(我的是.net项目)

百度编辑器UEditor与UEditor 公式插件完整Demo

2、下载UEditor公式插件

百度编辑器UEditor与UEditor 公式插件完整Demo

3、新建解决方案和项目

百度编辑器UEditor与UEditor 公式插件完整Demo

4、在浏览器中预览index.html页面

百度编辑器UEditor与UEditor 公式插件完整Demo

结果:

百度编辑器UEditor与UEditor 公式插件完整Demo

5、index.html源码

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>完整demo</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<script type="text/javascript" charset="utf-8" src="ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="ueditor.all.min.js"> </script>
<!--建议手动加在语言,避免在ie下有时因为加载语言失败导致编辑器加载失败-->
<!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型,比如你在配置项目里配置的是英文,这里加载的中文,那最后就是中文-->
<script type="text/javascript" charset="utf-8" src="lang/zh-cn/zh-cn.js"></script>
<!--公式编辑器-->
<script type="text/javascript" charset="utf-8" src="./kityformula-plugin/addKityFormulaDialog.js"></script>
<script type="text/javascript" charset="utf-8" src="./kityformula-plugin/getKfContent.js"></script>
<script type="text/javascript" charset="utf-8" src="./kityformula-plugin/defaultFilterFix.js"></script>
<style type="text/css">
div { width: 100%; }
</style>
</head>
<body> <div>
<h1>完整demo</h1>
<script id="editor" type="text/plain" style="width:1024px;height:500px;">
</script>
</div>
<div id="btns">
<div><button onclick="ReplaceImage()">imagebase64替换为image</button>
<button onclick="getAllHtml()">获得整个html的内容</button>
<button onclick="getContent()">获得内容</button>
<button onclick="setContent()">写入内容</button>
<button onclick="setContent(true)">追加内容</button>
<button onclick="getContentTxt()">获得纯文本</button>
<button onclick="getPlainTxt()">获得带格式的纯文本</button>
<button onclick="hasContent()">判断是否有内容</button>
<button onclick="setFocus()">使编辑器获得焦点</button>
<button onmousedown="isFocus(event)">编辑器是否获得焦点</button>
<button onmousedown="setblur(event)">编辑器失去焦点</button> </div>
<div>
<button onclick="getText()">获得当前选中的文本</button>
<button onclick="insertHtml()">插入给定的内容</button>
<button id="enable" onclick="setEnabled()">可以编辑</button>
<button onclick="setDisabled()">不可编辑</button>
<button onclick=" UE.getEditor('editor').setHide()">隐藏编辑器</button>
<button onclick=" UE.getEditor('editor').setShow()">显示编辑器</button>
<button onclick=" UE.getEditor('editor').setHeight(300)">设置高度为300默认关闭了自动长高</button>
</div> <div>
<button onclick="getLocalData()">获取草稿箱内容</button>
<button onclick="clearLocalData()">清空草稿箱</button>
</div> </div>
<div>
<button onclick="createEditor()">
创建编辑器
</button>
<button onclick="deleteEditor()">
删除编辑器
</button>
</div> <script type="text/javascript"> //实例化编辑器
//建议使用工厂方法getEditor创建和引用编辑器实例,如果在某个闭包下引用该编辑器,直接调用UE.getEditor('editor')就能拿到相关的实例
var ue = UE.getEditor('editor', {
toolbars: [['fullscreen', 'source', '|',
'undo', 'redo', '|',
'bold', 'italic', 'underline', 'superscript', 'subscript', 'pasteplain', '|',
'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', '|',
'paragraph', 'fontfamily', 'fontsize', '|',
'indent', 'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|',
'simpleupload', 'horizontal', 'inserttable', '|',
'searchreplace', 'kityformula'
]],
autoHeightEnabled: true,
autoFloatEnabled: true,
serverUrl: "/controller.ashx"
}); function ReplaceImage() {
ue.getKfContent(function (content) { });//将image的src从base64替换为文件名
}
function isFocus(e) {
alert(UE.getEditor('editor').isFocus());
UE.dom.domUtils.preventDefault(e)
}
function setblur(e) {
UE.getEditor('editor').blur();
UE.dom.domUtils.preventDefault(e)
}
function insertHtml() {
var value = prompt('插入html代码', '');
UE.getEditor('editor').execCommand('insertHtml', value)
}
function createEditor() {
enableBtn();
UE.getEditor('editor');
}
function getAllHtml() {
alert(UE.getEditor('editor').getAllHtml())
}
function getContent() {
var arr = [];
arr.push("使用editor.getContent()方法可以获得编辑器的内容");
arr.push("内容为:");
arr.push(UE.getEditor('editor').getContent());
alert(arr.join("\n"));
}
function getPlainTxt() {
var arr = [];
arr.push("使用editor.getPlainTxt()方法可以获得编辑器的带格式的纯文本内容");
arr.push("内容为:");
arr.push(UE.getEditor('editor').getPlainTxt());
alert(arr.join('\n'))
}
function setContent(isAppendTo) {
var arr = [];
arr.push("使用editor.setContent('欢迎使用ueditor')方法可以设置编辑器的内容");
UE.getEditor('editor').setContent('欢迎使用ueditor', isAppendTo);
alert(arr.join("\n"));
}
function setDisabled() {
UE.getEditor('editor').setDisabled('fullscreen');
disableBtn("enable");
} function setEnabled() {
UE.getEditor('editor').setEnabled();
enableBtn();
} function getText() {
//当你点击按钮时编辑区域已经失去了焦点,如果直接用getText将不会得到内容,所以要在选回来,然后取得内容
var range = UE.getEditor('editor').selection.getRange();
range.select();
var txt = UE.getEditor('editor').selection.getText();
alert(txt)
} function getContentTxt() {
var arr = [];
arr.push("使用editor.getContentTxt()方法可以获得编辑器的纯文本内容");
arr.push("编辑器的纯文本内容为:");
arr.push(UE.getEditor('editor').getContentTxt());
alert(arr.join("\n"));
}
function hasContent() {
var arr = [];
arr.push("使用editor.hasContents()方法判断编辑器里是否有内容");
arr.push("判断结果为:");
arr.push(UE.getEditor('editor').hasContents());
alert(arr.join("\n"));
}
function setFocus() {
UE.getEditor('editor').focus();
}
function deleteEditor() {
disableBtn();
UE.getEditor('editor').destroy();
}
function disableBtn(str) {
var div = document.getElementById('btns');
var btns = UE.dom.domUtils.getElementsByTagName(div, "button");
for (var i = 0, btn; btn = btns[i++];) {
if (btn.id == str) {
UE.dom.domUtils.removeAttributes(btn, ["disabled"]);
} else {
btn.setAttribute("disabled", "true");
}
}
}
function enableBtn() {
var div = document.getElementById('btns');
var btns = UE.dom.domUtils.getElementsByTagName(div, "button");
for (var i = 0, btn; btn = btns[i++];) {
UE.dom.domUtils.removeAttributes(btn, ["disabled"]);
}
} function getLocalData() {
alert(UE.getEditor('editor').execCommand("getlocaldata"));
} function clearLocalData() {
UE.getEditor('editor').execCommand("clearlocaldata");
alert("已清空草稿箱")
}
</script>
</body>
</html>

6、上传图片

修改config.json

百度编辑器UEditor与UEditor 公式插件完整Demo

百度编辑器UEditor与UEditor 公式插件完整Demo

这样的话上传的图片就会在网站根目录/UploadFiles/UEditor/image/20161122(这个名称根据时间变化)/底下

测试看看:

百度编辑器UEditor与UEditor 公式插件完整Demo

百度编辑器UEditor与UEditor 公式插件完整Demo

现在公式也可以用:

百度编辑器UEditor与UEditor 公式插件完整Demo

百度编辑器UEditor与UEditor 公式插件完整Demo

现在的图片还是base64的,然后把image的src从base64替换为文件名

百度编辑器UEditor与UEditor 公式插件完整Demo

替换好了

百度编辑器UEditor与UEditor 公式插件完整Demo的更多相关文章

  1. 【完整靠谱版】结合公司项目,仔细总结自己使用百度编辑器实现FTP上传的完整过程

    说在前面 工作中会遇到很多需要使用富文本编辑器的地方,比如我现在发布这篇文章离不开这个神器,而且现在网上编辑器太多了.记得之前,由于工作需要自己封装过一个编辑器的公共插件,是用ckeditor改版的, ...

  2. ueditor 百度编辑器图片上传 接 node&period;js 及一些前端自定义

    百度编辑器 用node.js 做服务端 demo 大神已整理的 记录一下 以作参考 https://github.com/netpi/ueditor 1. 前端图片工具栏上传input file在这里 ...

  3. Thinkphp 3&period;2&period;3配置百度编辑器(UEditor)

    Thinkphp 3.2.3配置百度编辑器(UEditor) 1.把百度编辑器放到项目的Public目录下 命名为:UEditor 2.找到thinkphp框架系统自带类中的Html.class.ph ...

  4. 百度地图 ijintui以及七牛、百度编辑器、kindeditor

    密码是明文存储的 sig错误是因为params没拼接上md5后的秘钥,测试时候可以在 Api\Controller\CommonController\_initialize 方法里注释掉效验的代码 代 ...

  5. Ueditor百度编辑器插件的安装

    目录 插件下载地址: 1. 引入 2. 编辑器显示处 id="content" 3.底部 4.ueditor编辑器按钮配置方法 定制工具栏图标 修改配置项的方法: 插件下载地址: ...

  6. &lbrack;转载&rsqb;百度编辑器-Ueditor使用

    前段时间发表过一篇关于“KindEditor在JSP中使用”的博文.这几天在沈阳东软进行JavaWeb方面的实习工作,在一个CMS系统的后台和博客板块中又要用到文本编辑器,突然发现了这个——百度编辑器 ...

  7. 又一编辑神器-百度编辑器-Ueditor

    (Lionden<hsdlionden@gmail.com> 转载说明) 前段时间发表过一篇关于“KindEditor在JSP中使用”的博文.这几天在沈阳东软进行JavaWeb方面的实习工 ...

  8. 百度编辑器ueditor前台代码高亮无法自动换行解决方法

    这两天本站成功安装整合了百度编辑器ueditor,用着还挺不错,但是遇到了点小问题 问题描述:   在内容里面插入代码高亮显示,后台编辑器中是可以自动换行的,但是发表后,在前台查看,发现代码不能自动换 ...

  9. 百度编辑器ueditor 使用

    ueditor 百度开源的一个 编辑器 ,支持api.扩展,demo丰富.推荐下 以前写 编辑 词典的使用 jquery-te  轻量级编辑器..当时看中了 它代码轻巧.容易改. 把他的功能改了好多. ...

随机推荐

  1. CGLib与JDKProxy的区别

    Spring AOP 的实现主要有两种:CGLib与JDK自带的Proxy. 他们主要的区别是,需要JDKProxy修改的类必须实现接口(因此也只能代理public方法),在创建Proxy时可以使用c ...

  2. &lbrack;HDOJ5791&rsqb;Two(DP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5791 题意:给两个数列,求有多少个公共子序列. dp(i,j)表示a1~ai和b1~bj的公共子序列个 ...

  3. JS一些小算术、1加到50、乘法口诀表、买鸡等

    //从1加到50 for (var a=1,i=0;a<51; a++) {i=a+i} document.write(i);//1加到50 var num=0; for(var i=1;i&l ...

  4. 关于bootstrap弹出二级对话框的使用

    弹出二级对话框,即在对话框的基础上再弹出一个对话框.这对于CRM管理类系统来说应用场景很常见.看到网上有关于实现二级弹出框的方法,需要在一级对话框页面上添加不少css样式.其实,完全可以不用这么麻烦. ...

  5. Android学习笔记之Spinner

    pinner就相当于Html中的下拉列表框,在下面的例子里我们共同学习一下spinner的使用. 属性: 属性名称 描述 android:prompt 该提示在下拉列表对话框显示时显示.(译者注:对话 ...

  6. Axure RP一个专业的快速原型设计工具

    Axure RP是一个专业的快速原型设计工具.Axure(发音:Ack-sure),代表美国Axure公司:RP则是Rapid Prototyping(快速原型)的缩写. Axure简要介绍 Axur ...

  7. Error&colon;java&colon; 无效的目标发行版&colon; 1&period;8

    出现问题: Error:java: 无效的目标发行版: 1.8 解决方法: file-setting--

  8. CentOS 7安装WordPress

    在开始本文前,我假定你已经安装好了nginx.php-fpm和mariaDB(或mysql).它们的安装过程可参考我以前的文章. 1. 安装EPEL(Extra Packages for Enterp ...

  9. &lbrack;连载&rsqb;Java程序设计&lpar;03&rpar;---任务驱动方式:寻找高富帅和屌丝

    版权声明:本文为博主原创文章,请在转载时说明出处. https://blog.csdn.net/jackfrued/article/details/26163877 任务:相同在上一家公司.公司还须要 ...

  10. &lbrack;Buzz Today&rsqb;2013&period;08&period;18

    # Go 语言实现memcached:groupcache memcached作者Brad Fitzpatrick用Go语言重新实现了memcached. groupcache继承了memcached ...