JQuery - 无法读取属性'编辑器'的未定义

问题描述:

我正在尝试几个所见即所得的HTML5/JQuery编辑器。但是,使用Bootstrap WISWYG和Summernote,我得到'无法读取'未定义'的属性''或'无法读取未定义属性'编辑器'。我只是在GitHub上使用标准文件。任何人使用JQuery插件熟悉这些错误?JQuery - 无法读取属性'编辑器'的未定义

编辑

我现在想Bootstrap WISWYG

在我的身体我有

<div id="editor">Editor</div> 

在我的JS,我有

$(document).ready(function() { 
    $('#editor').wysihtml5(); 
}); 

但是,错误我得到的是: 无法读取未定义(线157)的特性 '编辑'

行157:

var editor = new wysi.Editor(this.el[0], options); 

的jsfiddle:http://jsfiddle.net/MgcDU/8125/

EDIT 2

我忘了,包括一个JS文件。然而,包括它后,我得到一个新的错误:

Uncaught TypeError: Cannot read property 'firstChild' of undefined 

的代码行的错误是指:

if (isString) { 
    element = wysihtml5.dom.getAsDom(elementOrHtml, context); 
} else { 
    element = elementOrHtml; 
} 

while (element.firstChild) <<<Error 
+2

需要。更多。信息。 –

+0

尝试上传您的模拟jsfiddle或任何我们可以看到它(不)运行 – amenadiel

+0

*“无法读取未定义的属性'fn'最有可能意味着您没有在您的页面中包括jQuery – Phil

事情是你正在使用DIV元素,而不是textarea还有依赖关系丢失。检查引导WYSIHTML5页面,它说:

Dependencies:

  • bootstrap-wysihtml5.js
  • bootstrap-wysihtml5.css
  • wysihtml5
  • Twitter Bootstrap

然后你的文件应该是这个样子:

<!DOCTYPE html> 
<header> 
    <title>HTML5 Editor</title> 
    <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> 
    <!-- Of course place sources in your own server, do not leech bandwidth --> 
    <script type="text/javascript" src="http://jhollingworth.github.io/bootstrap-wysihtml5/lib/js/wysihtml5-0.3.0.js"></script> 
    <script type="text/javascript" src="http://jhollingworth.github.io/bootstrap-wysihtml5/lib/js/bootstrap.min.js"></script> 
    <script type="text/javascript" src="http://jhollingworth.github.io/bootstrap-wysihtml5/src/bootstrap-wysihtml5.js"></script> 
    <link rel="stylesheet" type="text/css" href="http://jhollingworth.github.io/lib/css/bootstrap.min.css"> 
    <link rel="stylesheet" type="text/css" href="http://jhollingworth.github.io/src/bootstrap-wysihtml5.css"> 
</header> 
<body> 
    <textarea class="editor"></textarea> 
    <script type="text/javascript"> 
     $(document).ready(function(){ 
      $('.editor').wysihtml5(); 
     }); 
    </script> 
</body> 

更多参考,请查阅:Wysihtml5 #Usage

+0

我错过了第三个文件,谢谢!但是,我收到了OP中包含的新错误。 – user2859066

+1

嗨,这是因为你试图添加编辑器到'DIV'而不是''元素。你用''替换了'

'吗? –

"cannot read property 'fn' of undefined" 

通常意味着脚本没有脚本被加载到DOM。你可能缺少jQuery文件?我常常注意到,它正在成为就在HTML的底部要加载的jQuery脚本的做法,之前

</body> 

好的,但是,它始终工作这么好,如果我在头只加载一个jQuery的文件,同时,其他的jquery插件脚本加载在html文件的底部。

+0

我在我的文件中包含了一个JQuery文件。其他脚本正在JQuery文件之后加载。 – user2859066

+0

有时以相反的顺序切换脚本。尝试一下。 – Faron

+0

我尝试了不同的命令。然而,看起来JQuery第一个WYSIHTML5第二个是正确的顺序,因为它没有说wysihtml5()不是函数。 – user2859066