jquery ocupload一键上传文件应用

直接上栗子

 

这是官方文档栗子

 1 var myUpload = $(element).upload({   
 2         name: 'file',   
 3         action: '',   
 4         enctype: 'multipart/form-data',   
 5         params: {},   
 6         autoSubmit: true,   
 7         onSubmit: function() {},   
 8         onComplete: function(response) {},   
 9         onSelect: function() {}   
10 });   
demo1
 1 $("#button-import").upload({  
 2     name: 'upload',  // <input name="file" />  
 3     action: '${pageContext.request.contextPath}/importSubarea.action',  // 提交请求action路径  
 4     enctype: 'multipart/form-data', // 编码格式  
 5     autoSubmit: true, // 选中文件提交表单  
 6     onComplete: function(response) {// 请求完成时 调用函数  
 7         if(response=="success"){  
 8             alert("数据导入成功!");  
 9         }  
10     }  
11 }); 
demo2

 

应用栗子

 1 //为导入按钮,添加一键上传效果
 2 $("#import").upload({
 3     //默认name为file
 4     action : 'xxx.action',
 5     onSelect : function(){
 6             //选中文件后,关闭自动提交
 7             this.autoSubmit=fasle;
 8             //判断文件格式,以.xls或者.xlsx结尾
 9             var filename = this.filename();
10             var regex = /^.*\.(xls|xlsx)$/;
11             if(regex.test(filename)){
12                 //满足
13                 this.submit();
14             } else {
15                 $.messager.alert("警告","只能上传.xls或者.xlsx文件!","warning");
16             }
17     },
18     onComplete : function(response){
19         alert("文件上传成功!");
20     }      
21 });                

 

转载于:https://www.cnblogs.com/zyh186/p/7289264.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值