首页 > uploadify如何获取$(this)?

uploadify如何获取$(this)?

先上图

目的

我要上传附件,然后上传成功之后,后台生成url,然后把url用a标签框起来添加到textarea里面供下载

问题

这个页面有好几个textarea和上传附件模块.....所以onuploadsuccess函数不能用id来获取textarea,所以我尝试用$(this).parent().children("textarea"),结果不起作用,此问题应该怎么解决呢?
HTML代码如下:

<dd class="filled">
<textarea name="key1" class="keyCloze" id="123456"></textarea>
<input type="file" class="uploadify">
<div id="fileQueue"></div>
<a href="javascript:$('#uploadify').uploadify('upload','*')" class="btn" >上传</a>
</dd> 

js如下

$(".uploadify").uploadify({
    'swf': 'uploadify.swf',
    'uploader': '',
    'queueID': 'fileQueue',
    'auto': false,
    'buttonText':'选择附件',
    'fileSizeLimit': 100,
    'multi': false,
    'width ': '90px',
    'fileTypeExts':'*.jpg;*.jpeg;*.png',
    'buttonClass':'uploadify-button',
    'onUploadSuccess' : function(file, data, response) {
        data = $.parseJSON(data);
        if(data.msg == "True"){
        var attachment_html = "<br><a href='" + data.attachment_url + "'>" + data.file_name + "</a>";
        var new_answer = $(this).parent().children("textarea").text() + attachment_html;
        $(this).parent().children("textarea").text(new_answer);
        }
    },
});

巧用闭包(手机码字)

$(".uploadify").each(function(){
var $this = $(this);
$this.uploadify({
    'swf': 'uploadify.swf',
    'uploader': '',
    'queueID': 'fileQueue',
    'auto': false,
    'buttonText':'选择附件',
    'fileSizeLimit': 100,
    'multi': false,
    'width ': '90px',
    'fileTypeExts':'*.jpg;*.jpeg;*.png',
    'buttonClass':'uploadify-button',
    'onUploadSuccess' : function(file, data, response) {
        data = $.parseJSON(data);
        if(data.msg == "True"){
        var attachment_html = "<br><a href='" + data.attachment_url + "'>" + data.file_name + "</a>";
        var new_answer = $this.parent().children("textarea").text() + attachment_html;
        $this.parent().children("textarea").text(new_answer);
        }
    },
});
});
【热门文章】
【热门文章】