关于百度富文本编辑框的UEditor的方法记录

本文档详细介绍了如何配置和使用富文本编辑器UEditor。首先展示HTML结构,包括`ueditor.all.js`等核心文件的引入。接着,通过创建jsp文件实现后台接口,处理编辑器的文件上传请求。最后,列举了一系列编辑器的方法,如设置内容、获取内容、焦点操作及各种编辑命令,帮助开发者更好地理解和应用富文本编辑器。
摘要由CSDN通过智能技术生成

HTML 部分(只需定义一个标签即可)

 <div style="width: 100%;">
    <script id="content" name="content" type="text/plain"></script>
 </div>

接下来就需要一个配置 然后引入js 实例化编辑器就可以使用了 但是后台肯定是没有的

<!-- 配置文件 -->
<script type="text/javascript" src="../ueditor/ueditor.config.js"></script>
<!-- 编辑器源码文件 -->
<script type="text/javascript" src="../ueditor/ueditor.all.js"></script>
<!-- 实例化编辑器 -->
<script type="text/javascript">
    var ue = UE.getEditor('content');
</script>

配置文件上传的路径在 config.json里配置
在这里插入图片描述
由前台访问后台,可以定义一个jsp 然后通过 ueditor.config.js 设置访问路径
在这里插入图片描述
jsp 内部配置:访问后台

<%@ page language="java" contentType="text/html; charset=UTF-8"
         import="com.nxzs.recruitstudent.ueditor.ActionEnter"
         pageEncoding="UTF-8" %>
<%@ page trimDirectiveWhitespaces="true" %>
<%
    request.setCharacterEncoding("utf-8");
    response.setHeader("Content-Type", "text/html");
    String rootPath = application.getRealPath("/");
    String action = request.getParameter("action");
    String result = new ActionEnter(request, rootPath).exec();
    if (action != null && (action.equals("listfile") || action.equals("listimage"))) {
        rootPath = rootPath.replace("\\", "/");
        result = result.replaceAll(rootPath, "/");
    }
    out.write(result);
%>

定义好后台的文件上传接口,富文本编辑框基本就可以了。
下面写一下富文本编辑框的一些方法

//实例化编辑器到id为 container 的 dom 容器上:
var ue = UE.getEditor('content');
//设置编辑器内容:
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');
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值