UEditor使用报错Cannot set property 'innerHTML' of undefined

来源:互联网 发布:华为mate7手机壳淘宝 编辑:程序博客网 时间:2024/05/06 05:50

仿用UEditor的setContent的时候报错,报错代码如下Uncaught TypeError: Cannot set property ‘innerHTML’ of undefined。调试ueditor.config.js,ueditor.all.js 提示me.body is undefined。(我就纳了闷儿了!同样的使用那个行这个咋就不行,那个有body,view,这个咋就这么少!【我还查看了插件的内部函数,真是个good媛~】)错误的原因是没有等UEditor创建完成就使用UEditor的setContent函数了,可以通过如下两种代码解决 :

  1. ueditor.addListener("ready", function () {
    ueditor.setContent('str');
    });
  2. ueditor.ready(function() {
    ueditor.setContent('str');
    });

ps:

 var ue = UE.getEditor('containerId');    var a  = "<%= info.C_Introdution || '' %>";    a = escape2Html(a);    $("#introdution").html(a);    function escape2Html(str) {        if(str.indexOf("&#34;")){            str = str.replace(/&#34;/ig,"&quot;");        }        var arrEntities={'&#34;':'"','lt':'<','gt':'>','nbsp':' ','amp':'&','quot':'"'};        return str.replace(/&(lt|gt|nbsp|amp|quot);/ig,function(all,t){return arrEntities[t];});    }    ue.ready(function() {        ue.setContent(a);        ue.addListener("contentchange", function () {            $("#introdution").html(ue.getContent());        })    });

js转换html转义字符

2 0
原创粉丝点击