JSP中使用CKEditor3.6入門教程__JSP

來源:互聯網
上載者:User

 CKeditor API CHM協助文檔 http://download.csdn.net/detail/guoquanyou/3622884

JSP頁面使用富文本控制項ckeditor提交表單資料

JSP頁面使用富文本控制項ckeditor自訂樣式

JSP使用ckeditor和ckfinder實現富文本及上傳功能


一、下載CKEditor

       1. 直接下載地址,當前最新版本為3.6:http://ckeditor.com/download

二、安裝CKEditor

       解壓ckeditor_3.5.zip,得到ckeditor檔案夾,將ckeditor整個檔案夾複製到項目工程的根目錄下,即WebRoot下 

三、驗證CKEditor是否安裝成功

       部署運行項目,訪問: http://localhost/項目名稱/ckeditor/_samples/index.html

       則可出現 “CKEditor Samples List” 的Demo頁面,說明CKeditor已安裝成功 

四、應用CKEditor

       1. 匯入JS檔案

            <script type="text/javascript" src="<%=request.getContextPath()%>/ckeditor/ckeditor.js"></script> 

       2. 建立和使用CKEditor

<%@ page language="java" import="java.util.*" pageEncoding="gbk"%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html>  <head>    <script type="text/javascript" src="<%=request.getContextPath()%>/ckeditor/ckeditor.js"></script><script type="text/javascript">   //<![CDATA[       CKEDITOR.replace('content',{toolbar:'Full', skin : 'kama'});   //]]>   </script>      <title>jCuckoo 's ckedit page</title>  </head>  <body>    <textarea class="ckeditor" cols="80" id="content" name="content" rows="10">        CKEditor Test......(此處的內容會在編輯器中顯示)</textarea>     </body></html>



        說明:

         1) textarea屬性值 name="content": 名字可隨意定義,但必須與下面的CKEDITOR.replace('content');匹配 

         2) CKEDITOR.replace('content');是最基本的寫法,表示使用CKEditor的JavaScript API建立的編輯器執行個體,

替換上面的textarea

若要為CKEditor增加一些屬性設定,則其屬性必須寫在{}花括弧內,

如上{toolbar:'Full', skin : 'kama'} 

五、擷取編輯器裡的資料

      有時在提交表單時,需要判斷下編輯器裡的內容是否為空白,這時可使用CKEditor的JavaScript API:

      CKEDITOR.instances.content.getData()      

function test() {    var editor_data = CKEDITOR.instances.content.getData();    if(editor_data==null || editor_data==""){        alert("請填寫內容。");        return false;    }}


      注意:如果你在編輯器裡打了一堆的空格,內容是不為空白的,因為編輯器會把你打的空格都轉換成&nbsp; 

至此,CKEdiotr編輯器即可在頁面上顯示與使用。 

補充說明:如果你的項目中使用struts2等架構,也可根據上面textarea的屬性name="content"來擷取編輯器裡的內容,最好使用BLOB來儲存。

 

 

 

 

 

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.