当前位置:网站首页>如何在一个页面上使用多个KindEditor编辑器并将值传递到服务器端
如何在一个页面上使用多个KindEditor编辑器并将值传递到服务器端
2022-06-24 09:40:00 【徊忆羽菲】
如何在一个页面上使用多个KindEditor编辑器并将值传递到服务器端
今天使用KindEditor编辑器时需要涉及到一个页面使用两个编辑器的问题,刚开始,我直接在添加和上面一样性质的代码,效果是出来了。但是提交的时候下面的那个值总是将上面的那个值覆盖了
1、声明一个editor数组:
var editor = new Array();
2、将之前的编辑器显示行代码:
KindEditor.ready(function(K) {
window.editor = K.create('#content', defaultEditorOptions);
});
变为一个索引数组形式的代码:
KindEditor.ready(function(K) {
window.editor[0] = K.create('#content', defaultEditorOptions);
window.editor[1] = K.create('#ycontent', defaultEditorOptions);
});
这样,KindEditor编辑器的效果图便会显示出来:
3、传递KindEditor所填写的相关数据:
之前一个KindEditor编辑器的传递方式是这样的:
<script>
$("#submitBtn").on('click', function(event) {
//编辑器中的内容异步提交
editor.sync();
event.preventDefault();
var params = $("form").serializeArray();
sendRequest('{:U("doEdit")}', params, function(data) {
if (data.status == 1) {
simpleSwal(data.info, '', 1, function() {
jumpCurrentFrame();
});
} else {
simpleSwal(data.info, '', 2);
}
});
});
<script>
我们需要将上述代码部分改为如下我们的正确传值方式:
$("#submitBtn").on('click', function(event) {
//编辑器中的内容异步提交
editor[0].sync();
editor[1].sync();//需要注意的是,这里面的索引数值是需要和变为一个索引数组形式的代码索引值一致,即键值一样多!!!
event.preventDefault();
var params = $("form").serializeArray();
sendRequest('{:U("doEdit")}', params, function(data) {
if (data.status == 1) {
simpleSwal(data.info, '', 1, function() {
jumpCurrentFrame();
});
} else {
simpleSwal(data.info, '', 2);
}
});
});
这样,我们就可以在服务器端进行相应值的接收和校验了。
下面把完整的代码贴下,需要的小伙伴可以看下:
<script>
// 点击提交
$("#submitBtn").on('click', function(event) {
//编辑器中的内容异步提交
editor[0].sync();
editor[1].sync();
event.preventDefault();
var params = $("form").serializeArray();
sendRequest('{:U("doEdit")}', params, function(data) {
if (data.status == 1) {
simpleSwal(data.info, '', 1, function() {
jumpCurrentFrame();
});
} else {
simpleSwal(data.info, '', 2);
}
});
});
</script>
<!-- 编辑器插件 -->
<script charset="utf-8" src="__PUBLIC__/lib/js/plugins/kindeditor/kindeditor.js"></script>
<script charset="utf-8" src="__PUBLIC__/lib/js/plugins/kindeditor/lang/zh_CN.js"></script>
<!-- 为避免kindeditor获取目录时出错,路径引入都避开base设置,采用根路径 -->
<!-- uploadJson等的路径默认是PHP的,可以不用配置。 -->
<!-- 但是若配置,则其相对路径起始是主窗口URL或者base,不是kindeditor自身的basePath -->
<script>
var editor = Array();
var defaultEditorOptions = {
width: '100%',
resizeType: 1,
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', '|', 'table', 'hr', 'emoticons',
'pagebreak', 'anchor', 'link', 'unlink', '|', 'about'
],
uploadJson: '{:U("imgUpload",array("f"=>"imgFile"))}',
formatUploadUrl: false,
// uploadJson: '__ROOT__/Public/lib/js/plugins/kindeditor/php/upload_json_extend.php',
afterUpload: function(url) {
}
};
KindEditor.ready(function(K) {
window.editor[0] = K.create('#content', defaultEditorOptions);
window.editor[1] = K.create('#ycontent', defaultEditorOptions);
});
</script>
边栏推荐
- CVPR 2022 Oral | 英伟达提出自适应token的高效视觉Transformer网络A-ViT,不重要的token可以提前停止计算
- How to manage massive network infrastructure?
- Five heart matchmaker
- CVPR 2022 oral | NVIDIA proposes an efficient visual transformer network a-vit with adaptive token. The calculation of unimportant tokens can be stopped in advance
- How does home office manage the data center network infrastructure?
- SQL sever基本数据类型详解
- PHP file lock
- PostgreSQL DBA快速入门-通过源码编译安装
- 411-栈和队列(20. 有效的括号、1047. 删除字符串中的所有相邻重复项、150. 逆波兰表达式求值、239. 滑动窗口最大值、347. 前 K 个高频元素)
- Analysis of 43 cases of MATLAB neural network: Chapter 32 time series prediction of wavelet neural network - short-term traffic flow prediction
猜你喜欢

利用pandas读取SQL Sever数据表

413 binary tree Foundation

Five heart matchmaker

Cicflowmeter source code analysis and modification to meet requirements

Go language development environment setup +goland configuration under the latest Windows

Floating point notation (summarized from cs61c and CMU CSAPP)

美国电子烟巨头 Juul 遭遇灭顶之灾,所有产品强制下架

411 stack and queue (20. valid parentheses, 1047. delete all adjacent duplicates in the string, 150. inverse Polish expression evaluation, 239. sliding window maximum, 347. the first k high-frequency

Analysis of 43 cases of MATLAB neural network: Chapter 32 time series prediction of wavelet neural network - short-term traffic flow prediction

vim的使用
随机推荐
微信小程序學習之 實現列錶渲染和條件渲染.
SSH Remote Password free login
二叉樹第一部分
Endgame P.O.O
canvas管道动画js特效
SQL-统计连续N天登陆的用户
Detailed explanation of PHP singleton mode
JS proxy mode
Thinkphp5 multi language switching project practice
CVPR 2022 Oral | 英伟达提出自适应token的高效视觉Transformer网络A-ViT,不重要的token可以提前停止计算
如何管理海量的网络基础设施?
SQL Sever中的窗口函数row_number()rank()dense_rank()
数组无缝滚动demo
形状变化loader加载jsjs特效代码
How large and medium-sized enterprises build their own monitoring system
dedecms模板文件讲解以及首页标签替换
[db2] sql0805n solution and thinking
Graffiti smart brings a variety of heavy smart lighting solutions to the 2022 American International Lighting Exhibition
2022-06-23: given a nonnegative array, select any number to make the maximum cumulative sum a multiple of 7, and return the maximum cumulative sum. N is larger, to the 5th power of 10. From meituan. 3
js代理模式