wangEditor的基本使用及踩坑记录

前言

最近写项目用到了富文本编辑器,在同事的建议下,采用了wangEditor3,在此记录下使用wangEditor3的基本步骤以及遇到的一些问题

 

基本使用

基本使用步骤原作者已讲的非常详细,如有需要,移步----->wangEditor3使用手册

下载

使用

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>wangEditor demo</title>
</head>
<body>
    <div id="editor">
        <p>欢迎使用 <b>wangEditor</b> 富文本编辑器</p>
    </div>

    <!-- 注意, 只需要引用 JS,无需引用任何 CSS !!!-->
    <script type="text/javascript" src="/wangE
  • 4
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 21
    评论
WangEditor是一款基于javascript和jQuery开发的富文本编辑器,它支持常见的文本编辑操作、图片上传和格式化等功能。如果您想对WangEditor进行二次封装和使用,可以按照以下步骤进行: 1. 下载WangEditor 您可以从官网上下载WangEditor的源码文件,也可以使用npm进行安装。 2. 引入WangEditorWangEditor的JS和CSS文件引入到您的HTML文件中: ```html <link rel="stylesheet" type="text/css" href="path/to/wangEditor.css"> <script type="text/javascript" src="path/to/jquery.js"></script> <script type="text/javascript" src="path/to/wangEditor.js"></script> ``` 3. 创建编辑器实例 在HTML文件中创建一个div元素,作为编辑器的容器,然后通过JavaScript代码创建编辑器实例: ```html <div id="editor"></div> <script type="text/javascript"> var editor = new wangEditor('editor'); editor.create(); </script> ``` 4. 配置编辑器 您可以通过传递配置对象来配置编辑器,例如: ```html <div id="editor"></div> <script type="text/javascript"> var editor = new wangEditor('editor'); // 配置编辑器 editor.config.uploadImgUrl = '/upload'; editor.config.uploadImgFileName = 'image'; editor.config.menus = [ 'bold', 'italic', 'underline', 'strikeThrough', 'eraser', 'foreColor', 'backColor', 'justifyLeft', 'justifyCenter', 'justifyRight', 'table', 'code', 'undo', 'redo' ]; editor.create(); </script> ``` 5. 使用编辑器 编辑器创建完成后,您可以使用它提供的方法来操作文本内容,例如: ```javascript // 获取编辑器内容 var content = editor.$txt.html(); // 设置编辑器内容 editor.$txt.html('<p>这是新的内容</p>'); ``` 以上就是二次封装和使用WangEditor基本步骤,您可以根据自己的需要进行配置和扩展。
评论 21
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值