仿用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函数了,可以通过如下两种代码解决 :
ueditor.addListener("ready", function () {
ueditor.setContent(‘str‘);
});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(""")){ ???????????str = str.replace(/"/ig,"""); ???????} ???????var arrEntities={‘"‘:‘"‘,‘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转义字符
UEditor使用报错Cannot set property 'innerHTML' of undefined
原文地址:http://www.cnblogs.com/Jeremy2001/p/7442076.html