在CkEditor上应用jQuery函数

时间:2012-07-06 04:22:45

标签: php jquery html ckeditor

我的html文件中有textarea,我需要将textarea中的数据发送到数据库。但是,textarea在没有enter空格的情况下发送数据。所以像这样的数据:

Shortly after reading a few books on web design, I was hooked. I wanted to know everything and anything about it. I was designing websites any chance I could. 

I spent almost all of my savings buying more books on different programming languages and other nerdy computer gear.

在数据库中会是这样的。

Shortly after reading a few books on web design, I was hooked. I wanted to know everything and anything about it. I was designing websites any chance I could. I spent almost all of my savings buying more books on different programming languages and other nerdy computer gear.

所以我决定将textarea更改为ckeditor以将数据发送为html。但问题是,我jQuery上有textarea方法,现在它无效。

HTML:

<td>
<textarea maxlength="5000" id="blah" cols="100" rows="20" name="essay_content" class="ckeditor" onkeyup="words();">
</textarea></td> 

jQuery的:

function words(content)
{
    var f = $("#blah").val()
    $('#othman').load('wordcount.php?content='+ encodeURIComponent(f));


}

现在它不适合我,因为文本区域是CkEditor ...有什么建议吗?

2 个答案:

答案 0 :(得分:0)

这应该可以获得CkEditor textarea的内容:

function words(content)
{
    var f = CKEDITOR.instances.blah.getData();
    $('#othman').load('wordcount.php?content='+ encodeURIComponent(f));
}

但是,我不认为onkeyup会起作用,因为CkEditor会替换textarea。您需要为CkEditor创建一个插件,以捕获编辑器实例中的键向上触发器。

答案 1 :(得分:0)

我使用了nlbr,一切正常。