为php增加kindeditor编辑器适合input、textarea亲测有效,适合新手教程
为php增加编辑器适合input、textarea亲测有效,适合新手教程:
用的是 kindeditor富文本编辑器,kindeditor 下载地址 : http://kindeditor.net/down.php
从官网下下来的 kindeditor 文件夹里取我们需要用到的几个目录:
直接放到项目静态资源文件里,随意哪个文件都可以,调用的时候路径正确就行。
在页面里引入本地富文本的js文件:(注意文件路径)
<link rel="stylesheet" href="/kindeditor/themes/default/default.css" />
<link rel="stylesheet" href="/kindeditor/plugins/code/prettify.css" />
<script charset="utf-8" src="/kindeditor/kindeditor-all.js"></script>
<script charset="utf-8" src="/kindeditor/lang/zh-CN.js"></script>
<script charset="utf-8" src="/kindeditor/plugins/code/prettify.js"></script>
然后再对应的渲染富文本编辑器
<script>
var editor1;
KindEditor.ready(function(K) {
editor1 = K.create('textarea[name="content"]',{
//参数配置
width : '95%',
uploadJson : '/assets/kindeditor/php/upload_json.php',
fileManagerJson : '/assets/kindeditor/php/file_manager_json.php',
minHeight: '600',
resizeType : 1,//禁止拉伸,1可以上下拉伸,2上下左右拉伸
filterMode: false,//true时过滤HTML代码,false时允许输入任何代码。
afterCreate : function() { this.sync(); }, //关键是这两个
afterBlur: function(){this.sync();},//关键是这两个
afterUpload: function(){this.sync();}, //图片上传后,将上传内容同步到textarea中
afterBlur: function(){this.sync();}, //失去焦点时,将上传内容同步到textarea中
itmes: [
'source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste',
'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
'superscript', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', '/',
'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image', 'multiimage',
'flash', 'media', 'insertfile', 'table', 'hr', 'emoticons', 'baidumap', 'pagebreak',
'anchor', 'link', 'unlink', '|', 'about'
]
}
);
// prettyPrint();
});
</script>
注意的地方就一处,textarea[name="content"],其中content就是针对textarea的,
到这里基本就好了,上传图片失败,请在kindeditor目录下,创建一个“attached”文件夹即可。
其他并未发现有什么问题。