1

我正在尝试几个所见即所得的 HTML5/JQuery 编辑器。但是,对于 Bootstrap WISWYG 和 Summernote,我得到“无法读取未定义的属性 'fn'”或“无法读取未定义的属性“编辑器”。我只是在 GitHub 上使用标准文件。任何人都熟悉使用 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/

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

2 回答 2

4

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

依赖项:

  • 引导-wysihtml5.js
  • 引导-wysihtml5.css
  • wysihtml5
  • 推特引导

那么您的文档应该类似于:

<!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

于 2013-11-28T00:46:58.220 回答
1
"cannot read property 'fn' of undefined" 

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

</body>

但是,如果我只在标题中加载了一个 Jquery 文件,同时在 html 文件的底部加载了其余的其他 jquery 插件脚本,它总是工作得很好。

于 2013-11-28T00:06:18.177 回答