zoukankan      html  css  js  c++  java
  • 【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=" 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() {
    
                }
            });
        });
    
    });
  • 相关阅读:
    QuickSort(Java)
    MergeSort(Java)
    Silverlight中Datagrid添加Button列用于控制单行对象
    二叉搜索树(BST)demo
    svn ignore使用方法
    海量数据处理面试题及解决方法
    Android中的单元测试
    Ubuntu下配置Intellij的Android开发环境
    urlrewrite地址重写之后丢失css和js解决方案
    修改后 简单的 TCP server
  • 原文地址:https://www.cnblogs.com/qlqwjy/p/7637386.html
Copyright © 2011-2022 走看看