[問題] jQuery each的變數範圍

看板Ajax作者時間14年前 (2011/08/24 16:59), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串1/1
我想做多個檔案上傳,再配合jquery的 progressbar這個plugin 目前的html是一個開始上傳的按鈕 <span id="start_upload" class="onclick">開始上傳</span> 和多個progressbar <div class="progress inline">20%</div> <div class="progress inline">30%</div> <div class="progress inline">40%</div> 我的js是這樣 $('.start_upload').click(function(){ //按下去之後,透過each $('.progress').each(function(){ setInterval(function() { $.getJSON("demo.php?id=" + progress_key, function(data) { if (data == null) return; var percentage = Math.floor(100 * parseInt(data.bytes_uploaded) / parseInt(data.bytes_total)); $(this).progressBar(percentage); //問題在這裡,怎麼指定是 each目前的物件 }); }, 1500); $(this).progressBar }); }); 請問我要怎麼把each 目前的索引的物件丟到setInterval 裡面去呢 謝謝回答 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 59.126.209.219

08/24 17:26, , 1F
each裡var t=$(this) 然後setInterval裡去找t
08/24 17:26, 1F
文章代碼(AID): #1ELBs7gQ (Ajax)
文章代碼(AID): #1ELBs7gQ (Ajax)