【kindeditor】kindeditor的使用

官网:http://kindeditor.net/demo.php

 

效果:

 

 

 

0.下载文档

1.引入核心文件(CSS与JS)

  items可以设置需要显示的控件

复制代码
<!-- 编辑器 -->
<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 editor;
    KindEditor.ready(function(K) {
        editor = K.create('textarea[name="liuyan.content"]', {
            resizeType : 1,
            allowPreviewEmoticons : false,
            allowImageUpload : true,
            pasteType : 0, //设置能否粘贴
            items : [ 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor',
                    'bold', 'italic', 'underline', 'removeformat', '|',
                    'justifyleft', 'justifycenter', 'justifyright',
                    'insertorderedlist', 'insertunorderedlist', '|',
                    'emoticons', 'image', 'link' ]
        });
        // 同步数据后可以直接取得textarea的value
        editor.sync();
    });
</script>
复制代码

 2.页面准备textarea

复制代码
        <!--编辑留言区域-->
        发表您的留言:<br />
        <form action="1.action" method="post" id="liuyanform">
            <textarea id="liuyan.content" name="liuyan.content"
                style="width: 100%;" class="el_editorBox"></textarea>
            <input type="hidden" name="liuyan.name"> <br>
            <p id="fabiao" class="btn btn-primary btn-sm" data-toggle="modal"
                data-target="#add">
                <span>发表</span>
            </p>
        </form>
复制代码

 

3.处理的JS函数

  判断编辑器是否为空以及获取编辑器的值异步ajax提交。

复制代码
/**
 * 
 * Created by liqiang on 2017/10/1.
 */
$(function() {
    /**
     * 提交按钮点击事件,内容不为空 的时候打开模态框输入姓名
     */
    $("#fabiao").click(function() {
        editor.sync();
        // 判断内容区是否为空
        if (editor.isEmpty()) {
            alert("内容不能为空!");
            return;
        }
        $("#tijiaomotai").modal();
    });
    $("#tijiao").click(function() {
        $("input[name='liuyan.name']").val($("input[name='name']").val());
        $.ajax({
            url : 'myBlog/liuyan_addLiuyan.action',
            data : {
                'liuyan.content' : editor.html(),
                'liuyan.name' : $("input[name='name']").val()
            },
            type : 'POST',
            async : true,
            success : function(data) {
                alert(data);
                window.location.href = 'liuyan_getLiuyans.action';
            },
            error : function() {

            }
        });
    });

});
复制代码

 

posted @   QiaoZhi  阅读(509)  评论(0编辑  收藏  举报
编辑推荐:
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· Obsidian + DeepSeek:免费 AI 助力你的知识管理,让你的笔记飞起来!
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
点击右上角即可分享
微信分享提示