2011-10-09 58 views
0

我使用jQuery uploadify插件上傳文件。 Each time I upload a file, a hidden field is created in the form with uploaded file path on server.當我提交表單時,我將該文件路徑從隱藏字段中存儲到數據庫中。它爲我工作。一個問題是我在uploadify的onComplete函數中硬編碼表單對象。如何獲得表單對象whos元素被點擊

這裏是我的代碼:

的jQuery:

 $('.FileUpload').uploadify({ 
     'uploader' : '/uploadify/uploadify.swf', 
     'script' : '/uploadify/uploadify.php', 
     'cancelImg' : '/uploadify/cancel.png', 
     'folder' : '/uploads', 
     'auto'  : true, 
     'queueID' : 'fileQueue', 
     'removeCompleted':false, 
     'onComplete' : function(event, ID, fileObj, response, data) { 
          // It is hard coded here. It may create probelems 
          // if there are multiple file upload buttons. 
          // How can I do this with '$(this)' keyword or something 
          $('.SingleFileUpload').parents('form').append('<input type="hidden" name="uploaded_file" value="' + response + '">'); 
         } 
     }); 

我怎樣才能只形成誰的文件瀏覽按鈕被點擊onComplete()功能。我認爲你明白了我的觀點?

感謝

回答

2

我認爲,如果你有$(event.target)

+0

感謝。它給了我一個方向。我也發佈了我的完整解決方案。謝謝。 – Student

0

更換$('.SingleFileUpload')我用以下解決我的問題,它應該工作:

$(event.target).closest('form').append('<input type="hidden" name="uploaded_file" value="' + response + '">');