layer进度条ajax,layui动态进度条详细。

首先 修改upload.js和layui.js

xhr:function () {

var newXhr = i.ajaxSettings.xhr();

// 给xhr的upload添加progress的监听

newXhr.upload.addEventListener('progress' , function (e) {

var percent = Math.floor(e.loaded / e.total * 100); //计算出进度

typeof l.progress === 'function' && l.progress(e , percent); // 传递给upload的progress回调

});

return newXhr;

},

将代码添加到如下位置

20181205113439605.png

demo中上传按钮

上传文件

js代码

layui.use(['upload','element','layer'], function(){

var upload = layui.upload;

var element = layui.element;

var layer = layui.layer;

element.init();

//执行实例

var uploa

你可能感兴趣的:(layer进度条ajax)