2012-08-17 30 views
0

從回調函數得到選擇我怎樣才能選擇傳遞給主函數如何從一個回調函數

$('.file_upload').uploadify({ 

     'uploader' : 'uploadify/uploadify.swf', 
     'script' : 'uploadify/uploadify.php', 
     'cancelImg' : 'uploadify/cancel.png', 
     'folder' : 'uploads', 
     'auto'  : true, 
     'buttonText': 'Upload a new file', 
     'onComplete' : function(event, ID, fileObj, response, data) { 
      //alert(fileObj.filePath); 

      //get the uploaded file txt and add it to the textbox 

      console.log(fileObj.filePath); 
      $.get('readfile.php?file='+fileObj.filePath, function (data) { 



      }); 

     // here I want to access the element the function called on 
     //$(this).parent().parent().find('textarea').val('this'); 

     } 
}); 
+1

你試過'event.target'嗎? – 2012-08-17 15:35:15

+0

非常感謝,這就是我要找的:) – Atef 2012-08-17 23:24:32

回答

1

發佈的答案評論...

原始的元素是event.target下可用:

$('.file_upload').uploadify({ 
    'onComplete' : function(event, ID, fileObj, response, data) { 
     // Wrap event.target in jQuery: $(event.target) 
     $(event.target).parent().parent().find('textarea').val('this'); 
    } 
}); 
1

你可以將它保存爲一個變量uploadify前:

var _file_upload = $('.file_upload'); 

//Then you can just do: 
_file_upload.jQueryStuffHere(); 
相關問題