最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to cause CKEditor textarea to refreshupdate with client side changes? - Stack Overflow

programmeradmin6浏览0评论

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.

The javascript works perfectly to populate any textarea.

It does not work when my textarea is my 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.

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?

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.

The javascript works perfectly to populate any textarea.

It does not work when my textarea is my 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.

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?

Share Improve this question edited Sep 3, 2013 at 11:13 Rory McCrossan 338k41 gold badges319 silver badges350 bronze badges asked Sep 3, 2013 at 11:10 DreamTeKDreamTeK 34.2k29 gold badges122 silver badges178 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 20

Use

CKEDITOR.instances['txtMailBody'].setData(result);

instead of

$('.CKE').val(result);

..When you update the CKEditored' textarea.


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

<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 only when 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.

发布评论

评论列表(0)

  1. 暂无评论