ueditor错误Cannot read property ‘nodeType‘ of undefined解决办法

今天在使用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();
            });

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
这个错误出现在代码中使用了sessionStorage属性但未定义的情况下。根据提供的引用内容,我们可以看到在第三个引用中有一段代码,其中使用到了window.sessionStorage.setItem方法来设置sessionStorage的值。这意味着在代码中应该已经正确引入了window对象,但是在某些情况下,可能会存在window对象未定义的情况,从而导致Cannot read property 'sessionStorage' of undefined错误。因此,需要检查代码中是否正确引入了window对象,并确保在使用sessionStorage属性之前,window对象已经被正确定义。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [sessionStorage.js](https://download.csdn.net/download/qq_27142569/12427911)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [ueditor 关闭页面后的报“Cannot read property 'lang' of undefined”。只渲染一次走一次ready事件](https://blog.csdn.net/qq_33769914/article/details/97764357)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [Cannot read property ‘$message‘ of undefined](https://blog.csdn.net/weixin_43131046/article/details/114584169)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值