如何从回调函数中获取选择器

时间:2012-08-17 15:27:48

标签: jquery callback

从回调函数

我怎样才能将选择器传递给main函数

$('.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');

        }
});

2 个答案:

答案 0 :(得分:1)

您可以在uploadify之前将其保存为变量:

var _file_upload = $('.file_upload');

//Then you can just do:
_file_upload.jQueryStuffHere();

答案 1 :(得分: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');
    }
});