【ueditor__使用】百度ueditor富文本编辑器
1、前言
在用户提交信息时,需要输入框提供换行设置字体样式大小等需求,普通input
和textarea
不能满足需求
2、使用百度开源富文本编辑器
需要注意的是js
引用顺序,zh-cn.js
汉化文件乱码时,需另存为UTF-8
格式,ueditor.configKikyo.js
文件是自定义编辑器的功能,详情参见文件内容
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title></title> </head> <body> <div> <!-- 加载编辑器的容器 --> <script id="container" name="content" type="text/plain"> </script> </div> <script src="http://code.jquery.com/jquery-2.1.4.min.js"></script> <script src="/lib/ueditor1_4_3_1/ueditor.configKikyo.js"></script> <script src="/lib/ueditor1_4_3_1/ueditor.all.min.js"></script> <!--zh-cn文件若乱码,另存为utf-8--> <script src="/lib/ueditor1_4_3_1/lang/zh-cn/zh-cn.js"></script> <script> var ue = UE.getEditor('container', { autoHeightEnabled: true, autoFloatEnabled: true, initialFrameWidth: 800, initialFrameHeight: 200 , serverUrl: "" //设置为空,浏览器不报上传接口错误 , wordCount: true //是否开启字数统计 , maximumWords: 300 //允许的最大字符数 , elementPathEnabled: false , toolbars: [['source', 'undo', 'redo', 'bold', 'justifyleft', 'justifycenter']] }); //对编辑器的操作最好在编辑器ready之后再做 ue.ready(function () { //设置编辑器的内容 ue.setContent('hello'); //获取html内容,返回: <p>hello</p> var html = ue.getContent(); //获取纯文本内容,返回: hello var txt = ue.getContentTxt(); console.log("html==", html); console.log("txt==", txt); }); </script> </body> </html>
自定义编辑器js如下
, toolbars: [[ 'undo', 'redo', '|' , 'bold', 'pasteplain', '|', , 'justifyleft', 'justifycenter', '|' , 'fontsize', '|' //'insertimage', 'insertvideo', '|' //, 'wordimage', '|' //, 'inserttable', 'insertrow', 'deleterow', 'insertcol', 'deletecol', 'mergecells', 'splittocells' ]]
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律