文件上传部分js

时间:2022-09-29 18:48:58
 
 
 
 
 
 
(function(){

var $WebUploadFile=function(resquestMapping,fileId){
    this.fileId=fileId+"BtnId";
    this.uploadPreId=fileId +"PreId"
    this.uploadUrl=路径;
        this.fileSizeLimit=100*1024*1024;
    this.uploadBarId=null;
};
$WebUploadFile.prototype={初始化WebUploadFile

init;funtion(){
var uploader=this.create();
return uploader;
},//创建WebUploadFile
create:function(){
vat webUploader=WebUploader.create({
auto:true,
pick:{
id:'#'+this.uploadBtnId,
multiple:false,

},
accept:{
title:'Files',
extensions:'txt,xls,xlsx',
mimiTypes:'file/txt,file/xls,file/xlsx'
}
swf:'../upload.swf',
disableGlobalDnd:true,
dupkicate:true,
server:this.uploadUrl,
fileSingleLimit:this.fileSizeLimt
});
return webUploader;
},//绑定事件
bindEvet:function(bindedObj){
var me=this;
bindedObj.on('uploadPregress',function(file,percentage){
parent.layer.load();
$("#"+me.uploadBarId).css("width",percentage*100+"%");
});
bindedObj.on('uploadSucess',function(file,response){
if(response.message){
    给出提示信息
}else{
    提示成功
}$("#"+me.pictureId).val(response)
});

bindedObj.on('uploadErr',function(file,response){
    提示失败信息
})
}
}
}())
 
引用html:
<uploadFile id="uploadFile  ...">
引用:js
var a=new WebUploadFile("",""uoloadFile);
a.setUploadBarId("progressBar");
a.init();
引用html:<uploadFile id="uploadFile" ...>