springboot+layui整合kindeditor富文本编辑器

最近用layui搭一个后台, 在发文章的时候有用到富文本编辑器 ,这里记录一下.

本人用的是 kindeditor富文本编辑器,因为layui自带的富文本感觉功能不是很多.

kindeditor 下载地址 :  http://kindeditor.net/down.php

从官网下下来的 kindeditor 文件夹里取我们需要用到的几个目录就行了

直接放到项目静态资源文件里  就行了

 

在页面里引入本地富文本的js文件  因为我用的是 springboot 所以静态资源路径直接用根路径就行了.

<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>

然后再对应的渲染富文本编辑器. 我把这一段放在 <head> 标签里了, 因为在layui的弹出层里可能会因为延迟加载不出来,所以直接放在head里加载.

    <script>
        var editor1;
        KindEditor.ready(function(K) {
             editor1 = K.create('textarea[name="content"]',{
                //参数配置
                width : '95%',
                     filePostName: "file",
                     uploadJson: '/fileupload/uploadArticleImg',
                minHeight: '600',
                    resizeType : 0,//禁止拉伸,1可以上下拉伸,2上下左右拉伸
                    filterMode: false,//true时过滤HTML代码,false时允许输入任何代码。
                    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>

其中 

uploadJson: '/fileupload/uploadArticleImg',是富文本里面上传图片的接口

textarea[name="content"]  对应 需要渲染成富文本的那个 textarea标签

然后就好啦

获取富文本的内容 只需要  

  editor1.html()  即可

    editor1.html(" 给富文本赋值")    也可以这样给富文本动态赋值. 

 

  • 4
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值