首页 > 代码库 > Ckeditor在线文本编辑器+键盘事件绑定

Ckeditor在线文本编辑器+键盘事件绑定

示例代码:

<%@ 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="http://www.mamicode.com/">
<title>Insert title here</title>
<script type="text/javascript" src=http://www.mamicode.com/‘#/‘" /ckeditor/ckeditor.js"></script>
<script type="text/javascript">
function test(){
    //获取文本数据
       var data = CKEDITOR.instances.content1.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;
    
}
</script>
</head>
<body>
<form action="" method="post">
    <textarea class="ckeditor" name="context" id="context"></textarea>
    <input  onkeyup="" onkeydown="" type="button" value="http://www.mamicode.com/提交" onclick="test()"/>
</form>
<div id="info"></div>
${param.context }
<script type="text/javascript">
 //键盘事件绑定
 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;
    
 });
 });
</script>
</body>
</html>


运行效果:

wKiom1RixcLgR-p7AAGBrGRn2BI527.jpg



本文出自 “老牛Java” 博客,谢绝转载!

Ckeditor在线文本编辑器+键盘事件绑定