简体   繁体   English

用 javascript 在 textarea 中设置 CKeditor 数据

[英]Set CKeditor data in the textarea with javascript

I have problem to set data in the ckeditor textarea.我在 ckeditor 文本区域中设置数据时遇到问题。 For example I need to set data <p><strong>Tilte</strong></p><p><i>123</i></p> in the textarea when I've clicked the save button, then the data will show in the textarea.例如,当我单击save按钮时,我需要在文本区域中设置数据<p><strong>Tilte</strong></p><p><i>123</i></p> ,然后数据将显示在文本区域中。

Below is I want the expected result:下面是我想要的预期结果:

输出

Below is my coding that I've tried, I've used this method CKEDITOR.instances[agenda_mesyuarat].setData(testing);下面是我尝试过的编码,我使用了这种方法CKEDITOR.instances[agenda_mesyuarat].setData(testing); but it cannot work.但它不能工作。

 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>

Hope someone can guide me on how to solve it.希望有人能指导我如何解决它。 Thanks.谢谢。

As you are assigning editor instance to theEditor, you can directly use it to set data in ckeditor.当您将编辑器实例分配给编辑器时,您可以直接使用它来设置 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>

I have the same problem, but in another way.我有同样的问题,但以另一种方式。

I am trying to.setData(bodyOfMyEmail), and then I also need to add signature using dropdown list, when I use dropdown list to select a signature to email it cleans all box and just write the signature.我正在尝试.setData(bodyOfMyEmail),然后我还需要使用下拉列表添加签名,当我使用下拉列表到 select 到 email 的签名时,它会清除所有框并只写签名。

How is it possible to do multiple setData() in this field without loosing previous one?如何在此字段中执行多个 setData() 而不会丢失前一个?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM