[英]Set CKeditor data in the textarea with javascript
我在 ckeditor 文本區域中設置數據時遇到問題。 例如,當我單擊save
按鈕時,我需要在文本區域中設置數據<p><strong>Tilte</strong></p><p><i>123</i></p>
,然后數據將顯示在文本區域中。
下面是我想要的預期結果:
下面是我嘗試過的編碼,我使用了這種方法CKEDITOR.instances[agenda_mesyuarat].setData(testing);
但它不能工作。
let theEditor; ClassicEditor.create(document.querySelector('#agenda_mesyuarat')).then(editor => { theEditor = editor; }).catch(error => { console.error(error); }); function getDataFromTheEditor() { return theEditor.getData(); } function send_1() { var testing = "<p><strong>Tilte</strong></p><p><i>123</i></p>"; CKEDITOR.instances[agenda_mesyuarat].setData(testing); }
<script src="https://cdn.ckeditor.com/ckeditor5/10.0.1/classic/ckeditor.js"></script> <textarea class="form-control" name="agenda_mesyuarat" id="agenda_mesyuarat" value="" title="Agenda Mesyuarat"></textarea><br><br> <button type="button" id="btn_save" value="Save" onclick="send_1()">Save</button>
希望有人能指導我如何解決它。 謝謝。
當您將編輯器實例分配給編輯器時,您可以直接使用它來設置 ckeditor 中的數據。
let theEditor; ClassicEditor.create(document.querySelector('#agenda_mesyuarat')).then(editor => { theEditor = editor; }).catch(error => { console.error(error); }); function getDataFromTheEditor() { return theEditor.getData(); } function send_1() { var testing = "<p><strong>Tilte</strong></p><p><i>123</i></p>"; theEditor.setData(testing); }
<script src="https://cdn.ckeditor.com/ckeditor5/10.0.1/classic/ckeditor.js"></script> <textarea class="form-control" name="agenda_mesyuarat" id="agenda_mesyuarat" value="" title="Agenda Mesyuarat"></textarea><br><br> <button type="button" id="btn_save" value="Save" onclick="send_1()">Save</button>
我有同樣的問題,但以另一種方式。
我正在嘗試.setData(bodyOfMyEmail),然后我還需要使用下拉列表添加簽名,當我使用下拉列表到 select 到 email 的簽名時,它會清除所有框並只寫簽名。
如何在此字段中執行多個 setData() 而不會丟失前一個?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.