首页 > 代码库 > 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(/ /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>
运行效果:
本文出自 “老牛Java” 博客,谢绝转载!
Ckeditor在线文本编辑器+键盘事件绑定
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。