分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 软件开发

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

发布时间:2023-09-06 01:06责任编辑:郭大石关键词:HTML

仿用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(""")){ ???????????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

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved