新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
layui使用upload組件實現(xiàn)文件上傳功能
背景:頁面上一個按鈕,點擊彈出上傳框,從按鈕的方法代碼開始寫:處理未選擇文件阻止上傳;通過判斷選擇文件的數(shù)量,顯示或隱藏上傳按鈕;

上海ssl適用于網(wǎng)站、小程序/APP、API接口等需要進行數(shù)據(jù)傳輸應用場景,ssl證書未來市場廣闊!成為成都創(chuàng)新互聯(lián)的ssl證書銷售渠道,可以享受市場價格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:18982081108(備注:SSL證書合作)期待與您的合作!
在js中定義:
function uploadFile(){
layer.open({
type:1,
title:'上傳文件‘,
area:['25%','400px'],
content:'\
\
\
\
\
\
\
\
\
\
\
‘,
btn:['關閉'],
btn1:function(idx,ele){
layer.closeAll();
}
})
createUpload();
}
var files ;
function createUpload(){
$("#uploadbtn").hide();
$("#chooseFile").next().next("span").text("");
layui.use(['upload'],function(){
var uploadInst = upload.render({
elem:'#chooseFile',
url:' ',
accept:'file',
auto:false,
multiple:true,
acceptMime:'application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
exts:'xls|xlsx',
size:1024000,
number:5,
bindAction:'#uploadbtn',
choose:function(obj){
files = this.files = boj.pushFile();
if(Object.keys(files).length>0){ $("#uploadbtn").show(); }
obj.preview(function(index,file,result){
$("#chooseFile").siblings("span").append(""+file.name+" ×")
if(index>0) {$("#uploadbtn").show() ;}
})
},
allDone:function(obj){
if(obj.successful){
layer.msg(obj.total+"個文件上傳成功!");
}
},
error:function(){
layer.alert("上傳成功!");
}
})
}
}
function deletefile(index){
delete files[index];
$("#chooseFile").siblings("span").find("div[title="+index+"]").remove();
if(!Object.keys(files).length>0){
$("#uploadbtn").hide();
}
}以上就是layui的upload組件使用和上傳阻止的詳細內(nèi)容,更多請關注創(chuàng)新互聯(lián)其它相關文章!
網(wǎng)站欄目:layui使用upload組件實現(xiàn)文件上傳功能
網(wǎng)頁網(wǎng)址:http://www.dlmjj.cn/article/ggpddj.html


咨詢
建站咨詢
