kindeditor demo下载:https://download.csdn.net/download/zj420964597/10602616
![](https://i-blog.csdnimg.cn/blog_migrate/e772709d571eb0a9112b8bac1c132f4d.png)
简单模式kindeditor的使用:
| <!doctype html> |
| <html> |
| <head> |
| <meta charset="utf-8" /> |
| <title>Simple Examples</title> |
| <style> |
| form { |
| margin: 0; |
| } |
| textarea { |
| display: block; |
| } |
| </style> |
| <link rel="stylesheet" href="../themes/default/default.css" /> |
| <script charset="utf-8" src="../kindeditor-min.js"></script> |
| <script charset="utf-8" src="../lang/zh_CN.js"></script> |
| <script> |
| $(function(){
kedit('textarea[name="content"]');
})
function kedit(s) {
KindEditor.create(s, {
resizeType : 1,
allowPreviewEmoticons : false,
allowImageUpload : false,
items : [
'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
'insertunorderedlist', '|', 'emoticons', 'image', 'link'],
afterCreate : function(){this.sync();},
afterBlur: function(){this.sync();}
});
}
//获取编辑器的内容
function getData() {
var content = $("input[name='content']").val();
alert(content); } |
| </script> |
| </head> |
| <body> |
| <h3>默认模式</h3> |
| <form> |
| <textarea name="content" style="width:100%;height:500px;" id="content"></textarea> <button type="button" class="btn btn-purple btn-round btn-info2" style="float: right; margin-top: 7px;" onclick="getData()" id="btn">
<span class="glyphicon"></span> 获取数据
</button> |
| </form> |
| </body> |
| </html> |
参考:
https://blog.csdn.net/yangzeqiang/article/details/7916949
https://blog.csdn.net/ameng001/article/details/9187067
http://www.cnblogs.com/mxxim/p/4565613.html
最近尝试用 nodeJS + angularJS + express 开发一个简单的文章管理系统项目。
发布文章采用的是KindEditor编辑器,一直用这个编辑器感觉还不错,官方文档的使用说明也很详细。然而,今天遇到了个奇葩问题,kindeditor-min.js以及css文件明明已经加载进来了,却进入不了KindEditor.ready(function(K){})里面。用以下代码测试了一下:
1 2 | console.log(KindEditor); console.log(KindEditor.ready()); |
控制台输出:
1 2 3 | function (a,b){ function c(a){a[0]||(a=[]); return new D(a)} if (!(a===i||a=== null )){ if ( typeof a=== "string" ){b&&(b=f(b)[0]); var d=a.length;a.charAt(0)=== "@" &&(a=a.substr(1)); if (a.length!==d||/<.+>/.test(a)){ var d=(b?b.ownerDocument||b:document).createElement( "div" ),e=[];d.innerHTML= '<img id="__kindeditor_temp_tag__" width="0" height="0" style="display:none;" />' +a; for ( var g=0,h=d.childNodes.length;g<h;g++){ var j=d.childNodes[g]; j.id!= "__kindeditor_temp_tag__" &&e.push(j)} return c(e)} return c(Ca(a,b))} if (a&&a.constructor===D) return a;a.toArray&&(a=a.toArray()); if (Z(a)) return c(a); return c(Ja(arguments))}} undefined |
说明KindEditor确实是已经定义了的。
后来换了一种方式来初始化创建编辑器,突然就好了。。不知道为什么会这样。。
原来的代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 | KindEditor.ready( function (K) { alert( "aa" ); window.editor = K.create( 'textarea[name="content"]' , { width: '1000px' , height: '1500px' , resizeMode: 0, allowPreviewEmoticons: false , items: [ 'bold' , 'italic' , 'underline' , '|' , 'justifyleft' , 'justifycenter' , 'justifyright' , 'insertorderedlist' , 'insertunorderedlist' , '|' , 'emoticons' , 'link' ] }); }); |
不能弹出“aa”
修改后的代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | function kedit(kedit){ var editor = KindEditor.create(kedit,{ width: '780px' , height: '700px' , resizeMode: 0, allowPreviewEmoticons: false , items: [ 'bold' , 'italic' , 'underline' , '|' , 'justifyleft' , 'justifycenter' , 'justifyright' , 'insertorderedlist' , 'insertunorderedlist' , '|' , 'emoticons' , 'link' ] }); } $( function (){ kedit( 'textarea[name="content"]' ); }) |