<button class="layui-btn layui-btn-sm uploadFile" data-keyId="id" data-val="' + row.id + '">上传</button>
// 加载成功后执行事件
ajaxSuccess: function (data) {
layui.upload.render({
elem: '.uploadFile'
, url: '${pageContext.request.contextPath}/uploadFile' //上传接口
, field: 'file'
, auto: true
, accept: 'file'
, before: function (obj) {
var key = this.elem.attr('data-keyId');
var val = this.elem.attr('data-val');
var buttonData = this.data
buttonData[key] = val;
if (layui.device().ie <= 9) {
for (var p in buttonData) {
if (typeof (buttonData[p]) == "function") {
buttonData[p]();
} else {
this.elem.parent().find('form[class=layui-upload-form]').eq(0).append('<input type="hidden" name="' + p + '" value="' + buttonData[p] + '">')
}
}
}
layui.layer.load();
}, done: function (res, index, upload) {
layui.layer.closeAll('loading'); //关闭loading
//上传完毕回调
if (res.status) {
layui.layer.alert("成功");
window.page();
} else {
layui.layer.msg("失败!");
}
},
error: function (index, upload) {
layui.layer.closeAll('loading'); //关闭loading
}
});
}