Kindeditor在线HTML富文本编辑器使用入门 (1)

KindEditor 是一套开源的 HTML 可视化编辑器,主要用于让用户在网站上获得所见即所 
得编辑效果,兼容 IE、Firefox、Chrome、Safari、Opera 等主流浏览器。 
这里写图片描述

kindeditor官方网站网址: 
http://kindeditor.net/demo.php 
这里写图片描述
这里写图片描述 
解压下载包,开发中只需要导入选中的文件(通常在 webapp 下,建立 editor 文件夹 )。 
这里写图片描述 
在HTML文件中导入相关js和css文件。 
这里写图片描述 
在文本域textarea中设置一个id的值为description。 
这里写图片描述
在js中创建一个kindeditor,将其嵌入到textarea中。 
这里写图片描述
完整代码:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>添加宣传任务</title>
        <!-- 导入jquery核心类库 -->
        <script type="text/javascript" src="../../js/jquery-1.8.3.js"></script>
        <!-- 导入easyui类库 -->
        <link rel="stylesheet" type="text/css" href="../../js/easyui/themes/default/easyui.css">
        <link rel="stylesheet" type="text/css" href="../../js/easyui/themes/icon.css">
        <link rel="stylesheet" type="text/css" href="../../css/default.css">
        <script type="text/javascript" src="../../js/easyui/jquery.easyui.min.js"></script>
        <script src="../../js/easyui/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
        <!--导入在线HTML编辑器 -->
        <script type="text/javascript" src="../../editor/kindeditor.js" ></script>
        <script type="text/javascript" src="../../editor/lang/zh_CN.js" ></script>
        <link rel="stylesheet" href="../../editor/themes/default/default.css" />

        <script type="text/javascript">
            $(function(){
                $("body").css({visibility:"visible"});
                $("#back").click(function(){
                    location.href = "promotion.html";
                });

                KindEditor.ready(function(K) {
                    window.editor = K.create('#description',{
                        items : [
                                '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'
                        ],
                        allowFileManager:true,
                        uploadJson : '../../image_upload.action',
                        fileManagerJson : '../../image_manage.action'
                    });
                });

                // 为保存按钮,添加click事件
                $("#save").click(function(){
                    if($("#promotionForm").form('validate')){
                        // 通过kindEditor数据到textarea 
                        window.editor.sync();
                        // 提交表单
                        $("#promotionForm").submit();
                    }else{
                        // 校验失败
                        $.messager.alert("警告信息","表单中存在数据非法项!","warning");
                    }
                });
            });
        </script>
    </head>
    <body class="easyui-layout" style="visibility:hidden;">
        <div region="north" style="height:31px;overflow:hidden;" split="false" border="false">
            <div class="datagrid-toolbar">
                <a id="save" icon="icon-save" href="#" class="easyui-linkbutton" plain="true">保存</a>
                <a id="back" icon="icon-back" href="#" class="easyui-linkbutton" plain="true">返回列表</a>
            </div>
        </div>
        <div region="center" style="overflow:auto;padding:5px;" border="false">
            <form id="promotionForm" enctype="multipart/form-data"
                action="../../promotion_save.action" method="post">
                <table class="table-edit" width="95%" align="center">
                    <tr class="title">
                        <td colspan="4">宣传任务</td>
                    </tr>
                    <tr>
                        <td>宣传概要(标题):</td>
                        <td colspan="3">
                            <input type="text" name="title" id="title" class="easyui-validatebox" required="true" />
                        </td>
                    </tr>
                    <tr>
                        <td>活动范围:</td>
                        <td>
                            <input type="text" name="activeScope" id="activeScope" class="easyui-validatebox" />
                        </td>
                        <td>宣传图片:</td>
                        <td>
                            <input type="file" name="titleImgFile" id="titleImg" class="easyui-validatebox" required="true"/>
                        </td>
                    </tr>
                    <tr>
                        <td>发布时间: </td>
                        <td>
                            <input type="text" name="startDate" id="startDate" class="easyui-datebox" required="true" />
                        </td>
                        <td>失效时间: </td>
                        <td>
                            <input type="text" name="endDate" id="endDate" class="easyui-datebox" required="true" />
                        </td>
                    </tr>
                    <tr>
                        <td>宣传内容(活动描述信息):</td>
                        <td colspan="3">
                            <textarea id="description" name="description" style="width:80%" rows="20"></textarea>
                        </td>
                    </tr>
                </table>
            </form>
        </div>
    </body>
</html>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/a772304419/article/details/78881918

KindEditor 是一套开源的 HTML 可视化编辑器,主要用于让用户在网站上获得所见即所 
得编辑效果,兼容 IE、Firefox、Chrome、Safari、Opera 等主流浏览器。 
这里写图片描述

kindeditor官方网站网址: 
http://kindeditor.net/demo.php 
这里写图片描述
这里写图片描述 
解压下载包,开发中只需要导入选中的文件(通常在 webapp 下,建立 editor 文件夹 )。 
这里写图片描述 
在HTML文件中导入相关js和css文件。 
这里写图片描述 
在文本域textarea中设置一个id的值为description。 
这里写图片描述
在js中创建一个kindeditor,将其嵌入到textarea中。 
这里写图片描述
完整代码:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>添加宣传任务</title>
        <!-- 导入jquery核心类库 -->
        <script type="text/javascript" src="../../js/jquery-1.8.3.js"></script>
        <!-- 导入easyui类库 -->
        <link rel="stylesheet" type="text/css" href="../../js/easyui/themes/default/easyui.css">
        <link rel="stylesheet" type="text/css" href="../../js/easyui/themes/icon.css">
        <link rel="stylesheet" type="text/css" href="../../css/default.css">
        <script type="text/javascript" src="../../js/easyui/jquery.easyui.min.js"></script>
        <script src="../../js/easyui/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
        <!--导入在线HTML编辑器 -->
        <script type="text/javascript" src="../../editor/kindeditor.js" ></script>
        <script type="text/javascript" src="../../editor/lang/zh_CN.js" ></script>
        <link rel="stylesheet" href="../../editor/themes/default/default.css" />

        <script type="text/javascript">
            $(function(){
                $("body").css({visibility:"visible"});
                $("#back").click(function(){
                    location.href = "promotion.html";
                });

                KindEditor.ready(function(K) {
                    window.editor = K.create('#description',{
                        items : [
                                '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'
                        ],
                        allowFileManager:true,
                        uploadJson : '../../image_upload.action',
                        fileManagerJson : '../../image_manage.action'
                    });
                });

                // 为保存按钮,添加click事件
                $("#save").click(function(){
                    if($("#promotionForm").form('validate')){
                        // 通过kindEditor数据到textarea 
                        window.editor.sync();
                        // 提交表单
                        $("#promotionForm").submit();
                    }else{
                        // 校验失败
                        $.messager.alert("警告信息","表单中存在数据非法项!","warning");
                    }
                });
            });
        </script>
    </head>
    <body class="easyui-layout" style="visibility:hidden;">
        <div region="north" style="height:31px;overflow:hidden;" split="false" border="false">
            <div class="datagrid-toolbar">
                <a id="save" icon="icon-save" href="#" class="easyui-linkbutton" plain="true">保存</a>
                <a id="back" icon="icon-back" href="#" class="easyui-linkbutton" plain="true">返回列表</a>
            </div>
        </div>
        <div region="center" style="overflow:auto;padding:5px;" border="false">
            <form id="promotionForm" enctype="multipart/form-data"
                action="../../promotion_save.action" method="post">
                <table class="table-edit" width="95%" align="center">
                    <tr class="title">
                        <td colspan="4">宣传任务</td>
                    </tr>
                    <tr>
                        <td>宣传概要(标题):</td>
                        <td colspan="3">
                            <input type="text" name="title" id="title" class="easyui-validatebox" required="true" />
                        </td>
                    </tr>
                    <tr>
                        <td>活动范围:</td>
                        <td>
                            <input type="text" name="activeScope" id="activeScope" class="easyui-validatebox" />
                        </td>
                        <td>宣传图片:</td>
                        <td>
                            <input type="file" name="titleImgFile" id="titleImg" class="easyui-validatebox" required="true"/>
                        </td>
                    </tr>
                    <tr>
                        <td>发布时间: </td>
                        <td>
                            <input type="text" name="startDate" id="startDate" class="easyui-datebox" required="true" />
                        </td>
                        <td>失效时间: </td>
                        <td>
                            <input type="text" name="endDate" id="endDate" class="easyui-datebox" required="true" />
                        </td>
                    </tr>
                    <tr>
                        <td>宣传内容(活动描述信息):</td>
                        <td colspan="3">
                            <textarea id="description" name="description" style="width:80%" rows="20"></textarea>
                        </td>
                    </tr>
                </table>
            </form>
        </div>
    </body>
</html>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110

猜你喜欢

转载自blog.csdn.net/yufang131/article/details/81019344