簡體   English   中英

在線文本編輯器無法使用我的JavaScript代碼

[英]Online text editor not working with my javascript code

我有一個在線文本編輯器“ CKEditor”,通過對其進行引用並為要與之協作的textarea命名一個特定的類名“ ckeditor”,該編輯器可以很好地與textarea配合使用,但是一旦我通過java添加了textarea腳本函數無需編輯器即可顯示文本區域,這是Java腳本代碼:

<script src="https://cdn.ckeditor.com/4.6.2/standard/ckeditor.js"></script>
<script>
function myFunction(){
    var target = document.getElementById("target"); 
    target.innerHTML = '<textarea name="editor1" class="ckeditor"></textarea>';
}
</script>

這是html代碼:

<!--the editor works with this textarea-->
<textarea name="editor1" class="ckeditor"></textarea>

<button onClick="myFunction()">runFunction</button>
<!--the div I want java script to place the editor by clicking the above button-->
<div id="target">some text</div>

有什么辦法嗎?

文檔中

 Use the CKEDITOR.replace() method to replace the existing <textarea> element with CKEditor. 

示例代碼顯示的位置:

 CKEDITOR.replace( 'editor1' ) 

其中editor1是文檔中文本區域的ID。

因此,給textarea一個ID,然后將其添加到文檔中后再調用該函數。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM