2013-11-27 92 views
1

我正在嘗試幾個所見即所得的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

回答

3

事情是你正在使用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'而不是''元素。你用''替換了'

'嗎? –

0
"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

相關問題