zoukankan      html  css  js  c++  java
  • 【ueditor__使用】百度ueditor富文本编辑器

    1、前言

    在用户提交信息时,需要输入框提供换行设置字体样式大小等需求,普通inputtextarea不能满足需求

    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'
            ]]
    

    ueditor1.4.3.1文件下载

  • 相关阅读:
    跳出语句 break continue
    循环语句 for循环、while循环、do while循环
    选择语句
    判断语句
    方法入门
    ++运算与--运算
    js面向对象的几种方式----工厂模式、构造函数模式、原型模式
    JavaScript This 的六道坎
    前端必备,十大热门的 JavaScript 框架和库
    localStorage、sessionStorage详解,以及storage事件使用
  • 原文地址:https://www.cnblogs.com/kikyoqiang/p/12900635.html
Copyright © 2011-2022 走看看