[問題] ajaxupload,起始物件的問題

看板Ajax作者 (Y)時間16年前 (2009/09/05 10:37), 編輯推噓1(102)
留言3則, 2人參與, 最新討論串1/1
大家好,我今天選用http://valums.com/ajax-upload/ 這個jquery的套件來上傳檔案 不過在設定上遇到一些問題 以下是我的code <button class=button id="buttonfile1">上傳圖片1</button> <button class=button id="buttonfile2">上傳圖片1</button> <button class=button id="buttonfile3">上傳圖片1</button> <button class=button id="buttonfile4">上傳圖片1</button> for(i=1;i<=4;i++) { newfile(i); } function newfile(file_id) { var button = $('#buttonfile'+file_id), interval; new AjaxUpload(button,{ action: "/SiteAdmin/update/update_company_image/award.html?lang=en&pic=award"+file_id, name: 'myfile', onSubmit : function(file, ext){ if (ext && /^(jpg|jpeg)$/.test(ext)){ button.text('上傳中..'); this.disable(); interval = window.setInterval(function(){ var text = button.text(); if (text.length < 8){ button.text(text + '.'); } else { button.text('上傳中..'); } }, 200); } else { alert("限傳jpg檔!!"); return false; } }, onComplete: function(file, response){ button.text('上傳圖片'+file_id); window.clearInterval(interval); this.enable(); if(response!='success') alert(response); else { $('#PImage'+file_id).attr("src", function() { return "/.DatawareHouse/.Temp/award/award"+file_id+".jpg?ts="+new Date().getTime(); }); alert('圖片'+file_id+'傳送成功'); } } }); } 主要是想要讓interval和button兩個變數名稱不要重複,這樣同時上傳才不會有問題 已試過把變數用陣列或是eval來代入,不過都會有error 請問一下正確的寫法應該要怎麼做比較好呢??感謝!! -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 123.194.162.170

09/10 12:46, , 1F
var button = '#buttonfile'+file_id; 這樣呢?
09/10 12:46, 1F

09/18 18:05, , 2F
ohoh~後面的沒問題,是變數名稱重複的問題
09/18 18:05, 2F

09/18 18:22, , 3F
試出來了var interval= new Array();interval[file_id]=
09/18 18:22, 3F
文章代碼(AID): #1AeSxoen (Ajax)
文章代碼(AID): #1AeSxoen (Ajax)