示例代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<%@ page language="java" contentType="text/html; charset=UTF-8"
     pageEncoding="UTF-8"%>
<%
     String path = request.getContextPath();
     String basePath = request.getScheme() + "://"
             + request.getServerName() + ":" + request.getServerPort()
             + path + "/";
%>    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
< html >
< head >
< base  href="<%=basePath%>">
< title >Insert title here</ title >
< script  type = "text/javascript"  src="<%=basePath %>ckk/ckeditor/ckeditor.js"></ script >
< script  type = "text/javascript" >
function test(){
     //获取文本数据
        var data = CKEDITOR.instances.context.getData();
     data = data.replace(/\s/g,'');
     data = data.replace(/<\/?[^>]*>/g,''); //去除HTML tag
     data = data.replace(/[ | ]*\n/g,'\n'); //去除行尾空白
     data = data.replace(/&nbsp;/ig,'');
     alert(data);
     document.getElementById("info").innerHTML= data;
     
     CKEDITOR.instances.content.setData('')
}
</ script >
</ head >
< body >
< form  action = ""  method = "post" >
     < textarea  class = "ckeditor"  name = "context"  id = "context" ></ textarea >
     < input    type = "button"  value = "提交"  onclick = "test()" />
</ form >
 
< div  id = "info" ></ div >
${param.context }
< script  type = "text/javascript" >
init();
function init(){
      //键盘事件绑定
      var editor = CKEDITOR.replace('context');
      CKEDITOR.instances["context"].on("instanceReady", function () {
      this.document.on("keyup", function(evt){
          //获取值
          var data = editor.getData();
          document.getElementById("info").innerHTML =data;
          //清空
          editor.setData('');
          //销毁
          editor.destroy(); 
          //删除
          //CKEDITOR.remove(editor);
         //重新绑定事件
         init();
         
      });
      });
}
</ script >
 
</ body >
</ html >


运行效果:

wKiom1RixcLgR-p7AAGBrGRn2BI527.jpg