【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() { } }); }); });
【当你用心写完每一篇博客之后,你会发现它比你用代码实现功能更有成就感!】
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· Obsidian + DeepSeek:免费 AI 助力你的知识管理,让你的笔记飞起来!
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了