使用UEditor时出错,报错代码如下:Uncaught TypeError: Cannot set property 'innerHTML' of undefined。调试半天发现需要等UEditor创建完成之后才能使用setcontent函数(郁闷)。找到解决方法有以下两种:
1.
ueditor.addListener("ready",function(){
ueditor.setContent('str');
});2.
ueditor.ready(function(){
ueditor.setContent('str');
});自己写的一个代码示例如下:
$(document).ready(function(){
var ue = UE.getEditor('editor');
ue.ready(function () {
var ke_txt_content = $("#ke-txt-content").val();
if(ke_txt_content){
ue.setContent(ke_txt_content);
}
ue.addListener("contentchange", function () {
$("#ke-txt-content").val(ue.getContent());
})
})
});