2015-05-07 60 views
1

我在JSP頁面中定義以下文本區域:CKEditor的使用setData()更改內容,而是拋出錯誤

<textarea id="edit_subtaskstep_notes" name="edit_subtaskstep_notes" rows="15" cols="50"></textarea> 

在我的js文件我設置的內容數據,例如:

CKEDITOR.instances.edit_subtaskstep_notes.setData("Hello World"); 

這個成功地設置ckeditor文本框在運行時包含「Hello World」,但在執行此行後,在我的輸出窗口中拋出以下錯誤:

Uncaught TypeError: undefined is not a function (14:21:03:488 | error, javascript) 
at (anonymous function) (:197:29) 

如果我刪除該行錯誤消失,但數據不再設置。由於數據設置的「似乎」工作,這是CKEditor v4的某種錯誤嗎?下載自述只是說「CKEditor 4」,但鏈接的版本(不會拋出錯誤)說4.4.7。

我已將代碼簡化爲以下單個文件,該文件仍然會重現錯誤。在線版本的包含擺脫了錯誤信息。下載的版本會引發錯誤。我沒有以任何方式修改下載包。正如我之前它說仍然是「作品」我只是不喜歡的錯誤消息:

<html> 
<head> 
    <meta http-equiv="content-type" content="text/html; charset=utf-8"> 

    <script src="js/vendor/jquery-1.11.0.js"></script> 
    <script src="/ckeditor/ckeditor.js"></script> 
    <!--<script src="//cdn.ckeditor.com/4.4.7/basic/ckeditor.js"></script>--> 
    <script> 
     $(document).ready(function() { 
      var editInstance = CKEDITOR.replace('editor1'); 
     }); 

     function onClickChangeText() { 
      CKEDITOR.instances.editor1.setData("Hello World"); 
     } 
    </script> 
</head> 

<body> 
    <textarea name="editor1" rows="10" cols="45"></textarea><br/> 
    <button onclick="onClickChangeText()">Change Text</button> 
</body> 

+0

CKEditor的版本是什麼?配置?加載插件列表?重現問題的示例(即JSFiddle)將是最好的。 – oleq

+0

我編輯顯示一個更簡單的例子。我無法使用JSFiddle,因爲我認爲問題出在他們的可下載軟件包上,因爲鏈接到在線版本會消除拋出的錯誤消息。 – NullByte

回答

1

望着在CKEDITOR下載區快速入門指南它說把解壓包的根網站。我試圖把它放在一個子目錄中並從那裏鏈接到它。我猜測主要的js文件試圖鏈接到它所需要的其他內部資源,這是基於root的,這將解釋我正在經歷的部分功能。將它移動到根後,錯誤消失了。

+1

您是否看到http://docs.ckeditor.com/#!/guide/dev_basepath? – Reinmar

+0

是的,但我沒有做任何這些事情。它開始再次向我拋出這個錯誤。如果我包含在線版本,它工作正常,但在使用基本下載包時仍然會出現此錯誤。我按照指示解壓並放入根。我仍然無能爲力,但因爲它的工作原理,我想我會忽略這個錯誤。 – NullByte

+0

所以也許它只是一個瀏覽器緩存?你清楚了嗎? – Reinmar

0
<!DOCTYPE html> 
<html lang="en"> 
<head> 
    <title>CKEditor Sample</title> 
    <script src="https://code.jquery.com/jquery-1.12.4.min.js" integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ=" crossorigin="anonymous"></script> 
    <script src="https://cdn.ckeditor.com/4.7.3/standard/ckeditor.js"></script> 
    <script> 
    var editInstance; 

    $(document).ready(function() { 
     editInstance = CKEDITOR.replace('editor1'); 
    }); 

    function onClickChangeText() { 
     editInstance.setData("Hello World"); 
    } 
    </script> 
</head> 
<body> 
    <textarea name="editor1" rows="10" cols="45"></textarea><br/> 
    <button onclick="onClickChangeText()">Change Text</button> 
</body> 
</html> 

試了一下上面的示例代碼對我來說在所有瀏覽器中都能正常工作。在控制檯中找不到錯誤。