layui 實現檔案上傳
阿新 • • 發佈:2019-02-09
專案需求:整合bootstrap + layui + java(MultipartFile) 實現 檔案上傳
js程式碼(可根據需要自行改成js或html頁面程式碼):
var g = '<button type="button" class="layui-btn demoMore" title="上傳檔案"
lay-data="{url: \'/dl_manager/dlManager/uploadFile?id=' + row.id + '\',
accept: \'file\'}" >上傳</button>';
layui 上傳介面繫結
layui.use ('upload', function () {
var upload = layui.upload;
//執行例項
var uploadInst = upload.render({
elem: '.demoMore', //繫結元素
//url: '/agentkey/agentKey/uploadOpenSSl', //上傳介面
size: 1000,
accept: 'file',
size:'204800', //kb
before: function (){
console.log('介面地址:'+ this.url, this.item, {tips: 1});
},
/* done: function (r) {
//layer.msg(r.msg);
if(r.code == 0){
parent.layer.msg(data.msg);
}
// app.getData().code;
}, */
done: function(res, index, upload){
var item = this.item;
console.log(item); //獲取當前觸發上傳的元素,layui 2.1.0 新增
reLoad();
},
error: function (r) {
//layer.msg(r.msg);
}
});
});