0

我对 javascript 和 jQuery 很陌生。我正在使用 Uploadify 将图像上传到服务器。页面上有多个 Uploader 对象。我需要将正在使用的 Uploader 对象的 id 传递给服务器。这是我到目前为止所拥有的:

$('input.ImageUpload').uploadify({
    ...
    'scriptData': {'id': ??????},
    ...
});

我怎样才能做到这一点?我试过“this.id”和“$(this).attr('id')”。我是否以正确的方式解决这个问题?

4

2 回答 2

2

我不确定这是否理想,但这就是我最终要做的:

$('input.ImageUpload').each(function() {
  $(this).uploadify({
    ...
    scriptData({'id': $(this).attr('id')},
    ...
  });
});
于 2010-02-21T00:29:46.550 回答
1

这就是我成功使用它的方式:

$(document).ready(function() {
    $(".upload").each(function() {
        $(this).uploadify({
            'uploader'      : '/code/js/jquery.uploadify/example/scripts/uploadify.swf',
            'script'        : '/code/js/jquery.uploadify/example/scripts/uploadify.php',
            'cancelImg'     : '/code/js/jquery.uploadify/example/cancel.png',
            'folder'        : '<?=$upload_path?>' + $(this).attr('id'),
            'queueID'       : 'fileQueue',
            'auto'          : true,
            'multi'         : false,
            'scriptData'        : ({'var_name': 'this_var_value'}),
            'fileDesc'          : 'Images and PDF files only! (JPG, PNG, PDF)',
            'fileExt'               : '*.pdf;*.jpg;*.jpeg;*.png',
            'buttonText'        : 'browse' +  $(this).attr('id')
        });
    });
});



<div id="fileQueue"></div>
<input class="upload" type="file" name="ImageUpload" id="_ID_1" /><br />
<input class="upload" type="file" name="ImageUpload" id="_ID_2" /><br />
<input class="upload" type="file" name="ImageUpload" id="_ID_3" /><br />
于 2010-04-09T13:55:51.247 回答