您的位置:首页 > 产品设计 > UI/UE

UEditor使用及Cannot set property 'innerHTML' of undefined 及Cannot read property 'replace' of undefine

2017-06-16 13:21 1161 查看
UEditor使用报错Cannot set property 'innerHTML' of undefined 及Cannot read property 'replace' of undefine

ueditor源码链接
http://download.csdn.net/download/u014793282/9872235
js引入顺序

<script type="text/javascript" charset="utf-8" src="{{ url_for('static', filename='ueditor-full/ueditor.config.js') }}"></script>

<script type="text/javascript" charset="utf-8" src="{{ url_for('static', filename='ueditor-full/ueditor.all.min.js') }}"> </script>

<script type="text/javascript" charset="utf-8" src="{{ url_for('static', filename='ueditor-full/ueditor.zh-cn.js') }}"></script>

html 部分

    <div style="width: 100%;">

    <h4>说明</h4>

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

</div>

<div id="btns" style="width: 100%;">

    <div >

        <button onclick="addContent()" style="background-color: #5ABBED;height:40px;margin-right: 30px;">提交</button>

    </div>

</div>

js部分

<script type="text/javascript">

//实例化编辑器

//建议使用工厂方法getEditor创建和引用编辑器实例,如果在某个闭包下引用该编辑器,直接调用UE.getEditor('editor')就能拿到相关的实例

    var ue = UE.getEditor('editor');

    function setContent(isAppendTo) {

        var arr = " ";

        $.ajax({

            url: "/get_doc_explain",

            // url: "/get_doc_explain?page=order",

            dataType: "json",

            json: "callback",

            type: "post", 

            data:{

                page:"order"

            },

            // request.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'),

            contentType: "application/x-www-form-urlencoded; charset=utf-8", 

            success: function (data) {

                  // arr.push("使用editor.setContent('欢迎使用ueditor')方法可以设置编辑器的内容");

                  var json  = data.entries;

                  // alert(json[0].content);

                  UE.getEditor('editor').setContent(json[0].content, isAppendTo);

                }

        });   

    }

    

    function addContent() {

        var arr = "";

        arr=UE.getEditor('editor').getContent();

        $.ajax({

            url: "/add_doc_explain" ,

            dataType: "json",

            json: "callback",

            type: "post", 

            data:{

                page:"order_",

                content:arr

            },

            contentType: "application/x-www-form-urlencoded; charset=utf-8", 

            success: function (data) {

                  alert("文档说明添加成功");

                  // window.location.reload;

            }

        });

    }

</script>

<script type="text/javascript">

    ue.ready(function() {

        setContent();    //  当使用 ue.setContent();  则会报错:Cannot read property 'replace' of undefine

    });

</script>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐