Uploadify:获取对象或父ID

时间:2012-11-15 01:22:37

标签: jquery uploadify

我有一个页面,文件上传输入可以通过后端自定义,所以我对uploadify的调用是在类上,如下所示:

$('.uploadify_upload').uploadify({
            'uploader'  : '../js/uploadify/uploadify.swf',
            'script'    : '../js/uploadify/uploadify.php',
            'cancelImg' : '../js/uploadify/cancel.png',
            'checkScript' : '../js/uploadify/check.php',
            'folder'    : '../img/uploads/temp/<?= $upload_temp_folder ?>/',
            'auto'      : true,
            'multi'     : false,
            'buttonText': 'Upload image',
            onComplete: function (event, queueID, fileObj, response, data) {
                $('#file_name').text(fileObj.name);
            }
        });

html看起来像:

<div class="image_preview" id="preview_<?= $field['field_name_in_channel_data'] ?>">
                                    <input type="file" class="uploadify_upload" id="upload_<?= $field['field_name_in_channel_data'] ?>" name="upload_<?= $field['field_name_in_channel_data'] ?>"/>
                                </div>

我希望能够在uploadify函数中获取div id(preview__..)或输入id(upload_...)。这样,我可以让后端知道上传的字段,以便稍后在DB中正确写入。我试过了

'onSelect'    : function(event,data) {
                    var div_id = $(this).parent().attr('id');
                    alert(div_id);

                },

其他但没有成功..我该怎么办?

1 个答案:

答案 0 :(得分:0)

这就是答案:

'onSelect'    : function(event,ID,fileObj) {
    var elem_id = $(event.target).attr("id"); //here you get the id of the object.
    $("#"+elem_id).uploadifySettings('scriptData',{'formID':elem_id})
},

来自Uploadify: Passing a form's ID as a parameter with scriptData