【问题标题】:Pass textarea value from WYSIWYG CKEditor从 WYSIWYG CKEditor 传递 textarea 值
【发布时间】:2014-03-15 09:44:46
【问题描述】:

我正在尝试将我在所见即所得编辑器(CK 编辑器)中所做的输入传递给 JQuery。目前,无论我输入什么,它都是空白的。

HTML:

<textarea type='text' class="ckeditor reply"  name='reply'></textarea>
<button type="button" STYLE="align: right;" class="btn btn-info reply_button yGreenButton">Submit Reply</button>

JS:

<script>
$(function()
{
    $('.reply_button').click(function(){

        var reply=$(this).siblings('.reply').val();

    });
});
</script>

文本区域显示为 CKeditor。无论我在 CKeditor textarea 中放什么,单击reply_button 发出的当前值都是空白的。如何让我输入的实际内容得到提醒?

非常感谢您的建议。

最好的,

【问题讨论】:

    标签: javascript jquery ckeditor textarea wysiwyg


    【解决方案1】:

    这是一个CKEditor,你必须使用他们的API:

    var editor = CKEDITOR.replace( '.ckeditor' );
    editor.getData();
    

    API 文档可以在here 找到。

    【讨论】:

    • 谢谢,但不幸的是它不起作用。原因是我实际使用了 class="ckeditor" 来替换 textarea,因此 editor.getData() 无法返回该值;它显示“未定义”错误
    【解决方案2】:

    你有两个选择——你可以直接使用 CKEditor API,或者 CKEditor 的 jQuery 适配器。

    要直接使用 CKEditor API,您需要编辑器实例。您可以使用相关textarea 的id 或name 或自动生成的名称('editor1'、'editor2' 等)从CKEDITOR.instances 对象中获取它。在你的情况下:

    var editor = CKEDITOR.instances.reply;
    var val = editor.getData();
    

    要使用 jQuery 适配器,您需要在 ckeditor.js 之后加载 adapters/jquery.js 文件,然后您可以轻松检索值:

    var val = $( '.ckeditor' ).val();
    

    就像您使用普通的textarea 一样。在jQuery adapter guide 中阅读更多内容并查看CKEditor with jQuery sample。

    【讨论】:

      猜你喜欢
      • 2021-12-14
      • 1970-01-01
      • 2011-12-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多