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

JQuery - cannot read property 'Editor' of undefined

本文关键字:编辑器 未定义 属性 JQuery- 读取      更新时间:2023-11-10

我正在尝试几个所见即所得HTML5/JQuery编辑器。然而,对于Bootstrap WISWYG和Summernote,我得到了未定义的"cannot read property"fn"或未定义的"不能读取property"Editor"。我只是在使用GitHub上的标准文件。有人熟悉使用JQuery插件时出现的这些错误吗?

编辑

我现在正在尝试Bootstrap WISWYG

我体内有

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

在我的js中,我有

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

但是,我得到的错误是:无法读取未定义(第157行)的属性"Editor"

第157行:

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

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

编辑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

问题是您使用的是DIV元素而不是textarea,还缺少依赖项。检查Bootstrap WYSIHTML5页面,它说:

依赖项:

  • 引导程序-wyshtml5.js
  • 引导程序-wyshtml5.css
  • wysihtml5
  • Twitter引导程序

然后你的文档应该看起来像:

<!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#用法

"cannot read property 'fn' of undefined" 

通常意味着脚本没有将脚本加载到DOM中。您可能缺少jQuery文件?我经常注意到,jQuery脚本在之前直接加载在HTML的底部已经成为一种惯例

</body>

但是,如果我在头中只加载了一个Jquery文件,同时在html文件的底部加载了其他Jquery插件脚本,那么它总是很好。