uploadify.js获取被点击项目的ID

时间:2015-06-04 11:44:17

标签: javascript jquery uploadify

我需要检索点击的按钮的ID,以使用uploadify()启动文件上传。我必须解析ID以从中提取一个数字并将其传递给我的upload.php脚本。 id的格式为:

upload_1
upload_2
.....
upload_XX

按钮(div)正在PHP中创建:

while (....) {
    echo "<div class='upload' id='upload_" . $row['did'] . "' data-role='none' title='UPLOAD DOCUMENTS'>";
}

我需要检索XX$row['did'])部分。

这是我的脚本:

<?php $timestamp = time();?>
$(function() {
    $('div[id*="upload_"]').uploadify({
        'buttonText'    : '&#x21e7;',
        'method'            : 'POST',
        'uploadLimit'  : 2,
        'width'             : 24,
        'height'        : 24,
        'title'         : 'UPLOAD DOCS',
        'buttonClass'   : 'uploadbutton',
        'swf'           : 'inc/uploadify/uploadify.swf',
        'uploader'      : 'inc/uploadify/uploadify.php',
        'onUploadStart': function (file, event) {
                alert($(this).attr("id"))
                $(this).uploadify('settings','formData',{
                    'driver': $(this).attr("id").toString().replace('upload_',''),
                    'timestamp' : '<?php echo $timestamp;?>',
                    'token'     : '<?php echo md5('unique_salt' . $timestamp);?>',
                })
        }
    });
});

console.log输出:

n.fn.init[1]0: SWFUploadbutton: n.fn.init[1]bytesLoaded: 0customSettings: ObjecteventQueue: Array[0]movieElement: object#SWFUpload_0.swfuploadmovieName: "SWFUpload_0"original: n.fn.init[1]queue: n.fn.init[1]queueData: Objectsettings: Objecttimer: 1433418517151wrapper: n.fn.init[1]__proto__: SWFUploadlength: 1__proto__: n[0]

1 个答案:

答案 0 :(得分:0)

 var Ids = new Array();

 $('#file_upload').uploadify({
        'uploader': SWFUrl,
        'script': AshxUrl,
        'cancelImg': cancelUrl,
        'folder': uploadsUrl,
        'auto': true,
        'fileExt': '*.jpg;*.gif;*.png;*.psd;*.jpeg',
        'fileDesc': 'Graphics Files',
        'removeCompleted': false,
        'buttonText': 'Upload PSD',
        'multi': true,
        'queueID': 'divParent',
        'onComplete': function (event, ID, fileObj, response, data) {
            Ids.push(response);
        },
'onSelect': function (event, ID, fileObj)
        {

            alert(event.target);
            alert($(event.target).prop('id'));
            customFileArray.push({ id: ID, file: fileObj, upload: false });
        }
    });

按照代码获取Value调用。

 $("#Ids").val(Ids.join(','));

只是省略了我使用的不需要的代码,我认为这足以让您理解

如果您还有问题,请告诉我