wangEditor 轻量级 web 富文本编辑器

17 篇文章 0 订阅

【介绍】

wangEditor 是基于javascript和css开发的 Web富文本编辑器, 轻量、简洁、易用、开源免费。

官网地址:http://www.wangeditor.com/

【下载】

【简单使用】

<!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="/wangEditor.min.js"></script>
    <script type="text/javascript">
        var E = window.wangEditor
        var editor = new E('#editor')
        // 或者 var editor = new E( document.getElementById('editor') )
        editor.create()
    </script>
</body>
</html>

 【复杂使用】

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>wangEditor demo</title>
    <style>
    	/* 富文本编辑器高度 */
        .w-e-text-container {
            height: 40rem !important;
        }
    </style>
</head>
<body>
    <div id="editor">
        <p>欢迎使用 <b>wangEditor</b> 富文本编辑器</p>
    </div>

    <!-- 注意, 只需要引用 JS,无需引用任何 CSS !!!-->
    <script type="text/javascript" src="./js/wangEditor.min.js"></script>
    <!-- 富文本 过滤word粘贴过来的字符串 -->
    <script type="text/javascript" src="./js/filterword.js"></script>

    <script type="text/javascript">
        var E = window.wangEditor;
        var editor = new E('#editor');
       
        // 自定义菜单配置
        editor.customConfig.menus = [
            'head',  // 标题
            'bold',  // 粗体
            'fontSize',  // 字号
            'fontName',  // 字体
            'italic',  // 斜体
            'underline',  // 下划线
            'strikeThrough',  // 删除线
            'foreColor',  // 文字颜色
            'backColor',  // 背景颜色
            'link',  // 插入链接
            'list',  // 列表
            'justify',  // 对齐方式
            'quote',  // 引用
            'emoticon',  // 表情
            'image',  // 插入图片
            'table',  // 表格
            'video',  // 插入视频
            'code',  // 插入代码
            'undo',  // 撤销
            'redo'  // 重复
        ];

        // 关闭粘贴样式的过滤
        editor.customConfig.pasteFilterStyle = true;

        // 忽略粘贴内容中的图片
        editor.customConfig.pasteIgnoreImg = false;

        // 自定义处理粘贴的文本内容
        editor.customConfig.pasteTextHandle = function (content) {
            //用来过滤word粘贴过来的字符串
            return returnHtml(content);
        }

        // 将图片大小限制为 3M
        editor.customConfig.uploadImgMaxSize = 3 * 1024 * 1024;

        // 下面两个配置,使用其中一个即可显示“上传图片”的tab。但是两者不要同时使用!!!
        // editor.customConfig.uploadImgServer = '/upload';  // 上传图片到服务器
        editor.customConfig.uploadImgShowBase64 = true;      // 使用 base64 保存图片
        
        //上传图片的错误提示
        editor.customConfig.customAlert = function (info) {
            alert(info);
        }

        //自定义上传图片事件 
        editor.customConfig.customUploadImg = function (files, insert) {
            var name = files[0].name; //文件对象
            var suffix = name.substr(name.indexOf(".")); //文件后缀名
            
        }

        editor.create();
        
        //设置内容 创建编辑器之后,使用editor.txt.html(...)设置编辑器内容
        //editor.txt.html('<p>用 JS 设置的内容</p>');
        
        //追加内容
        //editor.txt.append('<p>追加的内容</p>');
        
        //清空内容
        //editor.txt.clear();
        
        //读取内容
        //editor.txt.html(); //读取 html
        //editor.txt.text()  //读取 text
        
    </script>
</body>
</html>

用来过滤word粘贴过来的字符串的js文件地址:https://github.com/hujinchen/filterword

更多编辑器的配置,小伙伴们可以去看官网哦~

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
wangEditor是一款基于JavaScript和CSS开发的Web富文本编辑器,它具有轻量级、简洁、易用的特点。相比于普通的文本编辑器,富文本编辑器可以输入超越文本的数据内容,包括上传图片、输入表情、字体大小字号调整、颜色设置、对齐方式等功能操作。[1] 在使用wangEditor富文本编辑器时,首先需要在代码中引入相关的文件。可以在editor.vue文件中添加以下代码: ```html <template> <div> <div ref="editor" style="text-align:left"></div> </div> </template> <script> import E from 'wangeditor' export default { name: 'MyEditor', data() { return { editorContent: '', editor: null } }, props: { value: { type: String, required: true } }, model: { prop: 'value' }, methods: { getContent: function () { alert(this.editorContent) }, _initEditor(that) { var editor = new E(this.$refs.editor) editor.config.zIndex = 100 editor.create() that.editor = editor } }, mounted() { this._initEditor(this) setTimeout(() => { this.editor.txt.html(this.value) }, 1000) } } </script> <style scoped> </style> ``` 然后,可以在需要使用富文本编辑器的地方注册组件,并创建编辑器。可以使用以下代码: ```html <!-- 首先给出一个div,并设id属性 --> <div id="div1"></div> <script type="text/javascript"> var E = window.wangEditor var editor = new E('#div1') // 创建编辑器 editor.create() </script> ``` 以上是使用wangEditor富文本编辑器的基本介绍和使用方法。[1][2][3]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值