Ckeditor更新textarea [英] Ckeditor update textarea

查看:536
本文介绍了Ckeditor更新textarea的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想让ckeditor工作。显然它不使用textarea所以提交表单不提交在编辑器中的文本。 Beceause我使用多态关联等。我不能使一个onsubmit函数获取textarea的值(当提交表单时)。



所以我发现这个问题:使用jQuery从CKEditor的iframe抓取内容



有一些非常好的答案。发布的答案保持textarea最新。这是非常好的,只是我需要的!不幸的是,我不能让它工作。
有人知道为什么(例如)这不工作吗?



我有一个textarea(rails但它只是翻译成一个正常的textarea) br />

<%= f.text_area:body,:id =>'ckeditor',:rows => 3%>
/ p>

和以下js:

  if(CKEDITOR.instances.ckeditor){
CKEDITOR.remove(CKEDITOR.instances.ckeditor);
}
CKEDITOR.replace('ckeditor',
{
skin:'kama',
toolbar:[['Styles','Format',' ','Bold','Italic',' - ','NumberedList','BulletedList','Link']]


CKEDITOR.instances [ckeditor]。on(instanceReady,function()
{
//设置keyup事件
。 document.on(keyup,CK_jQ);

//并粘贴事件
this.document.on(paste,CK_jQ);
}

function CK_jQ()
{
CKEDITOR.instances.ckeditor.updateElement();
}

我在firebug中得到以下错误。


缺少)参数列表后
[ Break on this error] function CK_jQ()\\\

解决方案



我使用CKEditor版本3.6.1与jQuery表单提交处理程序。在提交textarea是空的,这对我是不正确的。但是有一个简单的解决方法,你可以使用,假设所有的CKEditor文本区域都有css类 ckeditor

  $('textarea.ckeditor')。each(function(){
var $ textarea = $(this);
$ textarea.val(CKEDITOR.instances [$ textarea.attr name')]。getData());
});

在执行提交处理之前执行上述操作。表单验证。


I am trying to get the ckeditor working. Obviously it doesn't make use of the textarea so on submit the form doesn't submit the text in the editor. Beceause I make use of polymorphic associations etc. I can't make a onsubmit function to get the value of the textarea (when the form is submitted) .

So I found this question: Using jQuery to grab the content from CKEditor's iframe

with some very good answers. The answers posted there keep the textarea up to date. That is very nice and just what I need! Unfortunately I can't get it to work. Does somebody know why (for example) this doesn't work?

I have a textarea (rails but it just translates to a normal textarea):
<%= f.text_area :body, :id => 'ckeditor', :rows => 3 %>

And the following js:

if(CKEDITOR.instances.ckeditor ) {
  CKEDITOR.remove(CKEDITOR.instances.ckeditor);
}
CKEDITOR.replace( 'ckeditor',
{
skin : 'kama',
toolbar :[['Styles', 'Format', '-', 'Bold', 'Italic', '-', 'NumberedList', 'BulletedList', 'Link']]});


CKEDITOR.instances["ckeditor"].on("instanceReady", function()
{
//set keyup event
this.document.on("keyup", CK_jQ);

//and paste event
this.document.on("paste", CK_jQ);
}

function CK_jQ()
{
 CKEDITOR.instances.ckeditor.updateElement(); 
}

I get the following "error" in my firebug.
missing ) after argument list [Break on this error] function CK_jQ()\n

解决方案

have you figured it out?

I'm using CKEditor version 3.6.1 with jQuery form submit handler. On submit the textarea is empty, which to me is not correct. However there is an easy workaround which you can use, presuming all your CKEditor textareas have the css class ckeditor.

$('textarea.ckeditor').each(function () {
   var $textarea = $(this);
   $textarea.val(CKEDITOR.instances[$textarea.attr('name')].getData());
});

Execute the above before you do your submit handling ie. form validation.

这篇关于Ckeditor更新textarea的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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