layui 文件上传加进度条
1.页面
<div class="layui-row layui-col-space5">
<div class="layui-form-item">
<label class="layui-form-label"><i class="i-red"></i>邀请说明</label>
<div class="layui-input-block">
<div class="layui-col-md2">
<button type="button" style="margin-top: 2px;" class="layui-btn" id="js_upload"><i class="layui-icon"></i>上传文件</button>
</div>
<div class="layui-col-md7">
<input type="text" name="fileName" autocomplete="off" maxlength="50" class="layui-input js_upload_file_name" value="${inviteMap.fname }" placeholder="" readonly="readonly">
</div>
</div>
</div>
<input type="hidden" name="fileId" class="js_resource_invite_file_id" value="${inviteMap.file_id }">
</div>
<!--弹出进度条-->
<div id="uploadLoadingDiv" style="display: none;">
<div class="layui-progress" lay-showpercent="true" lay-filter="js_upload_progress" style="margin: 10px;">
<div class="layui-progress-bar layui-bg-red" lay-percent="0%"></div>
</div>
<div class="layui-form-item" style="text-align: center">
<button class="layui-btn layui-btn-normal js_upload_progress_bar_sure" >确定</button>
</div>
</div>
2.upload.js 搜索ajax
$.ajax({
url: l.url
,type: l.method
,data: formData
,contentType: false
,processData: false
,dataType: 'json'
,xhr:l.xhr(function(e){//此处为新添加功能
var percent=Math.floor((e.loaded / e.total)*100);//计算百分比
l.progress(percent);//回调将数值返回
})
,success: function(res){
successful++;
done(index, res);
allDone();
}
,error: function(e){
console.log(e)
aborted++;
that.msg('请求上传接口出现异常');
error(index);
allDone();
}
});
3.js
layui.use(['form', 'layedit', 'laydate','element', 'upload','table'], function () {
var upload = layui.upload,form=layui.form,
element = layui.element,$=layui.$,table = layui.table,laydate=layui.laydate;
element.init();
form.render();
//日期初始化
laydate.render({
elem: '#date_start'
, type: 'datetime'
});
//创建监听函数
var xhrOnProgress=function(fun) {
xhrOnProgress.onprogress = fun; //绑定监听
//使用闭包实现监听绑
return function() {
//通过$.ajaxSettings.xhr();获得XMLHttpRequest对象
var xhr = $.ajaxSettings.xhr();
//判断监听函数是否为函数
if (typeof xhrOnProgress.onprogress !== 'function')
return xhr;
//如果有监听函数并且xhr对象支持绑定时就把监听函数绑定上去
if (xhrOnProgress.onprogress && xhr.upload) {
xhr.upload.onprogress = xhrOnProgress.onprogress;
}
return xhr;
}
} upload.render({
elem: '#js_upload',
url: gContextPath+"/uploadfile2.htm"
,multiple: false
,before:function(){
element.progress('js_upload_progress', '0%');//设置页面进度条
layer.open({
type: 1,
title: '上传进度',
closeBtn: 1, //不显示关闭按钮
area: ['300px', '170px'],
shadeClose: false, //开启遮罩关闭
content: $("#uploadLoadingDiv").html(),
offset: '100px'
});
}
,xhr:xhrOnProgress
,progress:function(value){//上传进度回调 value进度值
element.progress('js_upload_progress', value+'%');//设置页面进度条
}
,field: 'file'
, accept: 'images'
, data: {
"index": 1,
"appCbnid":""
},
accept: 'file',
//普通文件
done: function (res) {
console.log(res);
$(".js_upload_file_name").val(res[0].data.filename);
$(".js_resource_invite_file_id").val(res[0].data.fid);
},
error: function () {
layer.alert("上传失败",{offset: '100px'});
return false;
} }); //关闭进度条提示
$(document).on('click','.js_upload_progress_bar_sure',function(){
layer.close(layer.index);
}); });
layui 文件上传加进度条的更多相关文章
- jquery 实现拖动文件上传加进度条
通过对文件的拖动实现文件的上传,主要用到的是HTML5的ondrop事件,上传内容通道FormData传输: //进度条 <div class="parent-dlg" &g ...
- 纯H5 AJAX文件上传加进度条功能
上传代码js部分 //包上传 $('.up_apk').change(function () { var obj = $(this); var form_data = new FormData(); ...
- atitit.文件上传带进度条的实现原理and组件选型and最佳实践总结O7
atitit.文件上传带进度条的实现原理and组件选型and最佳实践总结O7 1. 实现原理 1 2. 大的文件上传原理::使用applet 1 3. 新的bp 2 1. 性能提升---分割小文件上传 ...
- atitit. 文件上传带进度条 atiUP 设计 java c# php
atitit. 文件上传带进度条 atiUP 设计 java c# php 1. 设计要求 1 2. 原理and 架构 1 3. ui 2 4. spring mvc 2 5. springMVC.x ...
- Springboot 文件上传(带进度条)
1. 相关依赖 pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http ...
- Asp.net mvc 大文件上传 断点续传 进度条
概述 项目中需要一个上传200M-500M的文件大小的功能,需要断点续传.上传性能稳定.突破asp.net上传限制.一开始看到51CTO上的这篇文章,此方法确实很不错,能够稳定的上传大文件,http: ...
- HTML5 + AJAX ( jQuery版本 ) 文件上传带进度条
页面技术:HTML5 + AJAX ( jQuery) 后台技术:Servlet 3.0 服务器:Tomcat 7.0 jQuery版本:1.9.1 Servlet 3.0 代码 package or ...
- springMVC+ajax 文件上传 带进度条
前端代码: <form id= "uploadForm"> <p >指定文件名: <input type="text" name= ...
- .Net neatupload上传控件实现文件上传的进度条
1. 引入bin文件 (可以到neatupload官网下载,也可以到教育厅申报系统中找) 2. 将控件加入到工具栏,在工具栏中点鼠标右键,如图: 3. 加入neatuplaod这个文件夹(可以到nea ...
随机推荐
- STM32 JTDO JREST复用为普通IO
一.开启AFIO的时钟(必须保证先打开AFIO,否则无效) RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE); 二.禁用JTAG,使能SWD GP ...
- BestCoder 1st Anniversary 1004 Bipartite Graph 【二分图 + bfs + 良好的逻辑思维 】
题目地址:http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?cid=610&pid=1004 问题描述 Soda有一个$ ...
- perl常用字符串函数
1.$position = index(string,substring,skipchars): 该函数返回子串substring在字符串string中的位置,如果不存在,则返回-1:参数skipch ...
- 转 Java Classloader机制解析
转 Java Classloader机制解析 发表于11个月前(2014-05-09 11:36) 阅读(693) | 评论(0) 9人收藏此文章, 我要收藏 赞1 慕课网,程序员升职加薪神器,点 ...
- 分享知识-快乐自己:PageHelper 分页关键基础代码
关键代码:点我下载样式 详细介绍 //使用分页插件 jQuery("#pagination").pagination(data.total, { items_per_page: ...
- [转载]C++Assert()函数
assert宏的原型定义在<assert.h>中,其作用是如果它的条件返回错误,则终止程序执行,原型定义: #include <assert.h> void assert( i ...
- leetcode 6 ZigZag Conversion(水题)
就是简单的模拟一下就可以了.但是我一开始是用一个二维char数组来存的,这样在最终扫全体时会扫很多空的位置,浪费了很多时间,所以就time limit error了. 所以改进一下就用string数组 ...
- 【leetcode刷题笔记】Minimum Depth of Binary Tree
Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shor ...
- windows 7下mingw+msys编译ffmpeg
windows 7下mingw+msys编译ffmpeg 1-->下载安装MingW,mingw-get-inst-20120426.exe http://sourceforge.ne ...
- ffmpeg第三方库编译记录
最近在研究ffmpeg的编译,之前使用的Ubuntu,需要安装虚拟机,非常麻烦,所以后来改研究在Windows平台编译. 一开始遇到很多挫折,参考了网上很多的帖子,但要么不全要么内容已过期,经过我的反 ...