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');

        }
});
4

2 回答 2

1

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

var _file_upload = $('.file_upload');

//Then you can just do:
_file_upload.jQueryStuffHere();
于 2012-08-17T15:29:47.790 回答
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');
    }
});
于 2012-08-19T02:15:30.520 回答