ckeditor 更新文本区域
我正在尝试让 ckeditor 工作。显然它没有使用文本区域,因此提交表单时不会在编辑器中提交文本。因为我使用多态关联等,所以我无法创建 onsubmit 函数来获取 textarea 的值(当提交表单时)。
所以我发现了这个问题: Using jQuery to scrap the content from CKEditor's iframe
有一些非常好的答案。那里发布的答案使文本区域保持最新。这非常好,正是我所需要的!不幸的是我无法让它工作。 有人知道为什么(例如)这不起作用吗?
我有一个文本区域(rails,但它只是转换为普通文本区域):
<代码> <%= f.text_area :body, :id => 'ckeditor', :rows => 3 %>
以及以下 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();
}
我在 Firebug 中收到以下“错误”。
<代码> 参数列表后缺少 ) [中断此错误] 函数 CK_jQ()\n
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(11)
以上所有答案都集中在如何修复此错误,但我想回答导致我出现此错误的原因,
我已更改
为
我将类属性值更改为 ckeditor 以外的任何内容,并且繁荣错误消失了。
希望有帮助
All above answer are focusing on how to fix this error but I want to take the answer on what cause me this error
I had a
changed to
I changed class attribute value to anything other than ckeditor and boom error gone.
Hope that help
最新版本的 CKEditor 进行了一些 API 更改,因此这里是 CKEditor 5 的答案:
据我所知,CKEditor 会在您提交表单时自动执行此操作,因此这个特定示例实际上不应该执行任何操作。但当您需要更新文本区域的内容而不提交包含它的表单时,它很有用。
There have been some API changes with the latest versions of CKEditor, so here's an answer for CKEditor 5:
To my knowledge, CKEditor does this automatically when you submit a form, so this particular example shouldn't actually do anything. But it is useful when you need the content of the textarea to udpate without submitting the form that contains it.
负载时:
On load:
我只是将其添加到 TJ 的响应中并为我工作:
I just increase that to the response of T.J. and worked for me:
只需添加
其中
textAreaClientId
是您的实例名称问候
Just Add
where
textAreaClientId
is your instance nameRegards
添加用于更新的函数 JavaScript
它的工作。凉爽的
ADD Function JavaScript for Update
It's work. Cool
将以上所有答案合二为一。
创建一个新的custom.js文件并添加以下内容:
您不必担心textarea的名称,只需在textarea中添加一个类
ckeditor
,上面就完成了。Combination of all of the above answers into one.
Create a new custom.js file and add this:
You don't have to worry about the name of the textarea, just add a class
ckeditor
in the textarea, the above and you are done.感谢@JohnDel 提供的信息,我使用 onchange 来更新每个更改。
Thanks @JohnDel for the info, and i use onchange to make it update every change.
你想出来了吗?
我正在使用 CKEditor 版本 3.6.1 和 jQuery 表单提交处理程序。提交时文本区域为空,这对我来说是不正确的。不过,您可以使用一个简单的解决方法,假设您的所有 CKEditor 文本区域都具有 css 类 ckeditor。
在进行提交处理之前执行上述操作。表单验证。
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.
Execute the above before you do your submit handling ie. form validation.
提交之前执行以下操作:
Before submit do: