2013-04-12 30 views
0

所以,我有以下重裝功能使onclick處理停止工作

<form id="uploadControls"> 
    <input type="file" id="browseFiles"> 
    <input type="button" id="startUpload" value="Upload"> 
    <input type="checkbox" id="overwrite"> 
</form> 

,而這些都是通過一些JavaScript用來控制文件上傳機制。後端工作得很好。我用resumable.js(https://github.com/23/resumable.js)這裏是我上傳的一個小樣本的片斷控制

var resume; 
function resumableUpload(){ 
    resume = new Resumable({ 
     url: uploadURL, 
     query: {overwrite: !!($("#overwrite").attr('checked'))}, 
     size: 1024*1024 
    }); 
    // some events with callback functions 
    resume.assignBrowse(document.getElementById("browseFiles")); 
} 
$("#startUpload").live("click",function(){ 
    resume.upload(); 
}); 

現在,如果有人來檢查複選框,允許文件覆蓋以前的現有(保存而不時間戳) ,我需要更新可恢復對象中的query參數,而我能夠做到的唯一方法是重新加載resumableUpload()。問題是,當呼叫通過像這樣做:

$("#overwrite").on('click',resumableUpload); 

然後所有的onclick處理程序停止響應。

我試過如下:

$("#overwrite").on('click',function(){ 
    $("#uploadControls").each(function(){ 
     this.reset(); 
    }); 
    startResumable(); 
}); 

但是,這似乎並沒有工作。

什麼我不這樣做是否正確?這與使用resumable.js庫綁定文件選擇器到<button>,但沒有在Firefox上工作正常工作,所以我需要一個更好的解決方案。

回答

0

嘗試使用代表團:

$("#uploadControls").on('click','#overwrite',function(){...}); 

BTW:

$("#startUpload").live("click",function(){...}); 

應該是:

$(document).live("click","#startUpload",function(){...}); 

LIVE被棄用:

從jQuery 1.7開始,不推薦使用.live()方法。使用.on()連接到事件處理程序 。老版本jQuery的用戶應該優先使用 .delegate(),而不是.live()。