开发者社区> 问答> 正文

uploadify如何获取$(this)?

screenshot目的

我要上传附件,然后上传成功之后,后台生成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);
        }
    },

展开
收起
小旋风柴进 2016-05-31 09:55:42 2129 0
1 条回答
写回答
取消 提交回答
  • $(".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);
            }
        },
    });
    2019-07-17 19:21:22
    赞同 展开评论 打赏
问答分类:
问答地址:
相关产品:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载