今天在使用ueditor的时候发现一个这样的报错。ueditor的css和js文件引入的路径没问题,不知道问题出在哪儿!
Uncaught TypeError: Cannot read property 'nodeType' of undefined
at Object.isEmptyBlock (ueditor.all.js:3938)
at UE.Editor.hasContents (ueditor.all.js:7690)
at UE.Editor.getContent (ueditor.all.js:7236)
at companyInfo.html:71
isEmptyBlock @ ueditor.all.js:3938
hasContents @ ueditor.all.js:7690
getContent @ ueditor.all.js:7236
(anonymous) @ companyInfo.html:71
最后排查发现,原因出在页面加载的时候直接获取ueditor的内容,在页面加载的时候ueditor应该还没有渲染好,直接获取是拿不到的。
这样会报错,页面加载的时候我们从ueditor中加载内容是没有任何意义的,因此还是把它放到保存的方法里面,或者等待ueditor加载完成以后再使用其获取内容/设置内容的方法。
ue.ready(function () {
//设置内容用下面方法
ue.setContent("要设置的内容");
//获取内容使用下面的方法
ue.getContent();
});