Javascript 未捕获类型错误:无法读取属性';添加';未定义的tinymce版本4.x

Javascript 未捕获类型错误:无法读取属性';添加';未定义的tinymce版本4.x,javascript,jquery,tinymce,Javascript,Jquery,Tinymce,我使用的是tiny mce 4.x版本,这是我在html文件中编写的代码 <script type="text/javascript" src="tinymce/tinymce.min.js"></script> <script> tinymce.init({ selector: "textarea#elm1", theme: "modern", width: 500, height: 300, plugins

我使用的是tiny mce 4.x版本,这是我在html文件中编写的代码

 <script type="text/javascript" src="tinymce/tinymce.min.js"></script>
 <script>
   tinymce.init({
    selector: "textarea#elm1",
    theme: "modern",
    width: 500,
    height: 300,
    plugins: [
         "advlist autolink link image lists charmap print preview hr anchor pagebreak spellchecker",
         "searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking",
         "save table contextmenu directionality emoticons template paste textcolor"
   ],
      content_css: "css/content.css",
      toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image | print preview media fullpage | forecolor backcolor emoticons", 
       style_formats: [
           {title: 'Bold text', inline: 'b'},
           {title: 'Red text', inline: 'span', styles: {color: '#ff0000'}},
           {title: 'Red header', block: 'h1', styles: {color: '#ff0000'}},
           {title: 'Example 1', inline: 'span', classes: 'example1'},
           {title: 'Example 2', inline: 'span', classes: 'example2'},
           {title: 'Table styles'},
           {title: 'Table row 1', selector: 'tr', classes: 'tablerow1'}
      ],
     setup : function(ed) {
        ed.onBeforeRenderUI.add(function(ed, cm) {
         console.log('add function called');
       });
       ed.onLoadContent.add(function(ed, o) {
           console.log('add function called');
      });
}


}); 

tinymce.init({
选择器:“textarea#elm1”,
主题:“现代”,
宽度:500,
身高:300,
插件:[
“advlist autolink图像列表charmap打印预览hr锚定页面中断拼写检查器”,
“searchreplace wordcount visualblocks visualchars代码全屏插入日期时间媒体非中断”,
“保存表格上下文菜单方向性表情模板粘贴文本颜色”
],
content\u css:“css/content.css”,
工具栏:“插入文件撤消重做|样式选择|粗体斜体|对齐左对齐中心对齐右对齐对齐对齐对齐|粗体numlist outdent缩进|链接图像|打印预览媒体全页|前景色背景色表情”,
样式和格式:[
{标题:“粗体文本”,内联:“b'},
{标题:'Red text',内联:'span',样式:{color:'#ff0000'}},
{title:'Red header',block:'h1',style:{color:'#ff0000'}},
{title:'example1',inline:'span',classes:'example1'},
{title:'example2',inline:'span',classes:'example2'},
{title:'表格样式'},
{title:'Table row 1',选择器:'tr',类:'tablerow 1'}
],
设置:功能(ed){
ed.onbeforerendrui.add(函数(ed,cm){
log('addfunction called');
});
ed.onLoadContent.add(函数(ed,o){
log('addfunction called');
});
}
}); 


我发现了错误

未捕获的TypeError:在以下情况下无法读取未定义的属性“add” 调用onBeforeRenderUI.add()方法


。请帮助我解决这个问题。谢谢。

感谢您分享一个适合您的解决方案。 但要正确:问题的解决方案是使用tinymce 4代码(onLoadContent仅使用tinymce 3)。 正确的使用方法是:

 setup : function(ed) {
    ed.on('BeforeRenderUI', function(e) {
     console.log('BeforeRenderUI function called');
   });
   ed.on('LoadContent', function(e) {
       console.log('LoadContent function called');
  });

嗨,我用setAttribute代替setup解决了这个问题
 setup : function(ed) {
    ed.on('BeforeRenderUI', function(e) {
     console.log('BeforeRenderUI function called');
   });
   ed.on('LoadContent', function(e) {
       console.log('LoadContent function called');
  });