1.定义一个隐藏的按钮,用于绑定渲染upload
<button id="uploadCaseBtn" type="button" style="display: none"></button>
可定义caseUpload为全局变量
caseUpload = upload.render({ elem: '#uploadCaseBtn' //绑定元素 , url: '/admin/system/file/uploadCaseFile' , accept: 'file' //普通文件 , acceptMime: 'application/pdf' , exts: 'pdf' , done: function (res) { //上传完毕回调 var data = res.data; } , error: function () { layer.msg("上传失败,请稍后重试"); } });
2.动态生成的html代码绑定onclick事件 uploadCaseFile。caseUpload全局变量后可以重装参数,只需要最后调用之前隐藏按钮的点击事件就可以调用upload方法了。不需要动态去渲染upload
function uploadCaseFile(id,type) { caseUpload.reload({ data: { id: id, uploadType:type } }); $("#uploadMeetBtn").click(); }