jquery 插件ajaxupload 的簡單應用
阿新 • • 發佈:2018-01-19
button 操作 6.5 shang disable pan 成功 簡單應用 verify
當然這些代碼得靠 js 才能運行,請把上面的代碼加在 $(document).ready的代碼塊中.同時請引入 ajaxupload.js,見附件下載!
- var button = $(‘#upload_button‘); //定義能夠上傳文件的按鈕,就是一個普通的button
- var fileType = "zip",fileNum = "one"; //定義能夠上傳的文件類型,當然要靠後面的onSubmit中的js去做判斷
- new AjaxUpload(button,{
- action: ‘${ctp}/app/assistVerify/importShanghairReportAction.shtml‘,
- name: ‘shanghaiFile‘, //這相當於<input type = "file" name = "shanghaiFile"/>
- onSubmit : function(file, ext){
- if(fileType == "zip")
- {
- if (ext && /^(zip|rar)$/.test(ext)){
- this.setData({
- ‘info‘: ‘文件類型為壓縮包‘ //這個info 暫時無效
- });
- } else {
- alert(‘非壓縮包類型文件,請重傳‘);
- return false;
- }
- }
- button.text(‘導入上海資信中...‘);
- if(fileNum == ‘one‘) //同時上傳的文件數不能超過一個
- this.disable();
- },
- onComplete: function(file, response){ //上傳完畢後的操作
- if(response != "success")
- alert(response);
- button.text(‘導入上海資信‘);
- this.enable();
- if(response == "success");
- alert("導入上海資信成功");
- //有了response我們能做任何事了,返回的文件名稱,文件路徑等我們可以隨意操作的!
- }
- });
當然這些代碼得靠 js 才能運行,請把上面的代碼加在 $(document).ready的代碼塊中.同時請引入 ajaxupload.js,見附件下載!
- ajaxupload.rar (6.5 KB)
- 下載次數: 427
jquery 插件ajaxupload 的簡單應用