[英]How can we populate textarea value when textarea is initilized as ckeditor
好吧,我一直在使用 HTML 表单开发 CKEDITOR,后端是 asp.net core v3.1。 我在渲染和绑定 html 表单中使用了 asp 标签助手。
以下是代码:
<div class="form-group">
<label asp-for="Content" class="control-label"></label>
<div class="input-group">
<textarea asp-for="Content" class="form-control" required placeholder="Content"></textarea>
<span asp-validation-for="Content" class="text-danger"></span>
</div>
</div>
我有两个页面创建和编辑,它们分别创建数据库的第一个表单条目并更新值。
因此,当我加载编辑页面时,所有值都已加载,但 CKEditor 值在它绑定到 textarea 之后并未加载。
值未显示在 HTML CKEDITOR 内容区域中。
CKEDITOR INITILIZE CODE IS BELOW
<script>
// Replace the <textarea id="editor1"> with a CKEditor
// instance, using default configuration.
$(function () {
CKEDITOR.replace('Content');
})
</script>
}
API 文档为此记录了方法:
CKEDITOR.instances.editor1.setData( '<p>This is the editor data.</p>' );
var element = CKEDITOR.dom.element.createFromHtml( '<img src="hello.png" border="0" title="Hello" />' );
CKEDITOR.instances.editor1.insertElement( element );
CKEDITOR.instances.editor1.insertText( ' line1 \n\n line2' );
插入 HTML 。
CKEDITOR.instances.editor1.insertHtml( '<p>This is a new paragraph.</p>' );
我认为您需要的是setData
作为其他方法在光标位置附加 text/html 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.