vb.net 如何使 CKEditor textarea 刷新/更新客户端更改?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18590787/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to cause CKEditor textarea to refresh / update with client side changes?
提问by DreamTeK
SCRIPT
脚本
$('.DDL').change(function update() {
$.get('../Folder' + $(this).val() + '.html', function(result) {
$('.CKE').val(result);
});
});
TEXTAREA
文本区域
<asp:CKEditorControl ID="txtMailBody" CssClass="CKE" RunAt="Server" BasePath="~/Editor"/>
I have some jscript that populates my textareas with relevant content based on their selection.
我有一些 jscript 根据他们的选择用相关内容填充我的文本区域。
The javascript works perfectly to populate any textarea.
javascript 可以完美地填充任何文本区域。
It does not work when my textarea is my ckeditor.
当我的 textarea 是我的 ckeditor 时它不起作用。
Inspecting the page reveals that the content is being added but the ckeditor does not display it. Refreshing the page also causes the content to appear.
检查页面显示正在添加内容,但 ckeditor 不显示它。刷新页面也会导致内容出现。
QUESTION
题
How can I cause a CKEditor textarea to refresh / update to show client side code that has been added on the fly from a dropdownlist?
如何使 CKEditor textarea 刷新/更新以显示已从下拉列表中动态添加的客户端代码?
回答by davidkonrad
Use
用
CKEDITOR.instances['txtMailBody'].setData(result);
instead of
代替
$('.CKE').val(result);
..When you update the CKEditored' textarea.
..当您更新 CKEditored 的文本区域时。
Try this little demo :
试试这个小演示:
select box with text snippets to be inserted :
选择带有要插入的文本片段的框:
<select id="test">
<option>some text to be inserted</option>
<option>some other text</option>
<option>even more text</option>
</select>
A textarea that becomes a CKEditor instance
成为 CKEditor 实例的 textarea
<textarea id="txtMailBody"></textarea>
script
脚本
//create the CKEditor instance
CKEDITOR.replace("txtMailBody");
$("#test").change(function() {
var result = $("#test option:selected").text();
//HERE
CKEDITOR.instances['txtMailBody'].setData(result);
//instead of $(textarea).val(result);
});
It is of course onlywhen the target is a CKEditor you should use CKEDITOR.instances['txtMailBody'].setData(result);, otherwise - if it is a textarea, use the code you already have.
当然,只有当目标是 CKEditor时才应该使用CKEDITOR.instances['txtMailBody'].setData(result);,否则 - 如果它是 textarea,请使用您已有的代码。

