2012-07-06 15 views
0

我在我的html文件中有一個textarea,我需要將textarea中的數據發送到數據庫。但是,textarea發送的數據沒有enter空格。所以這樣的數據:在CkEditor上應用jQuery函數

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。但現在的問題是,我在textarea上有一個jQuery方法,現在它不起作用。

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

使用['nl2br'](http://php.net/manual/en/function.nl2br.php)與textarea。不要使用CK編輯器來解決空白問題。 – diEcho 2012-07-06 04:30:39

回答

0

這應該讓你的CKEDITOR textarea的內容:

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

但是,我不認爲onkeyup將工作,因爲CKEDITOR取代textarea的。你需要爲CkEditor創建一個插件來捕捉編輯器實例中的鍵盤觸發器。

0

我已經使用nlbr,一切正常。