如何改变CKEditor文本使用jQuery? [英] How change the CKEditor text using jQuery?

查看:146
本文介绍了如何改变CKEditor文本使用jQuery?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个CKEditor的文本区域(bbCode插件)。

I have a textarea with CKEditor (bbCode Plugin).

<textarea id="editor1" name="conteudo" class="form-control" rows="3" required></textarea>

这是我的CKEditor实例:

This is my CKEditor instance:

$( document ).ready( function() {
    $( 'textarea#editor1' ).ckeditor();
} );

我正在进行 JSON 需要一个值,我希望这个值在 textarea 中修改,我尝试与 jQuery 但不工作!
以下是我的尝试:

I'm making a JSON request that takes a value and I want this value to be modified in this textarea, I tried with jQuery but not worked ! Below is my attempt:

video_id = "lLi1Lx2xTKI";

$.getJSON('http://gdata.youtube.com/feeds/api/videos/'+video_id+'?v=2&alt=jsonc',function(data,status,xhr){
    description = data.data.description;
    // Attempt here
    $("#editor1").html(description);
});

UPDATE

我尝试使用'.val()'而不起作用!

I tried using '.val()' and not worked!

推荐答案

你不能简单地添加文本到CKEDITOR通过jQuery,而不是使用CKEDITOR给出的 api

You can't simply add text to the CKEDITOR via jQuery, instead go with api given by CKEDITOR

CKEDITOR.instances.editor1.setData(data.data.description); 

这里您的代码看起来像

$.getJSON('http://gdata.youtube.com/feeds/api/videos/'+video_id+'?v=2&alt=jsonc',function(data,status,xhr){   
    CKEDITOR.instances.editor1.setData(data.data.description); 
});

Fiddle

这篇关于如何改变CKEditor文本使用jQuery?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆