2013-02-25 119 views
4

我正在使用ckeditor撰寫電子郵件,我使用它生成的html發送html電子郵件廣告我也需要文本版本,所以同時具有HTML和電子郵件中的純文本版本將避免垃圾郵件。如何從ckeditor生成html中提取純文本在JAVA

從java中的ckeditor html代碼中獲取文本的方法是什麼?

回答

12

這是很簡單的JavaScript調用:

CKEDITOR.instances.yourEditorInstance.getData() 

返回:

<h1>Apollo 11</h1>  
<p><b>Apollo 11</b> was the spaceflight that landed the first humans, Americans <a href="http://en.wikipedia.org/wiki/Neil_Armstrong" title="Neil Armstrong">Neil Armstrong</a> and <a href="http://en.wikipedia.org/wiki/Buzz_Aldrin" title="Buzz Aldrin">Buzz Aldrin</a>, on the Moon on July 20, 1969, at 20:18 UTC. Armstrong became the first to step onto the lunar surface 6 hours later on July 21 at 02:56 UTC.</p> 

但是:

CKEDITOR.instances.yourEditorInstance.editable().getText() 

返回:

Apollo 11 
Apollo 11 was the spaceflight that landed the first humans, Americans Neil Armstrong and Buzz Aldrin, on the Moon on July 20, 1969, at 20:18 UTC. Armstrong became the first to step onto the lunar surface 6 hours later on July 21 at 02:56 UTC. 
+1

getText()在一行中顯示所有內容。不在下一行顯示第二張「阿波羅11號」 – 2016-09-23 15:36:04