我很新的JavaScript和jQuery。我使用Uploadify上传图片到服务器。有在页面上的多个上传对象。我需要通过上传对象的ID被用于服务器。这是我到目前为止有:

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

我怎样才能做到这一点?我已经试过 “this.id” 和 “$(本).attr( '身份证')”。上午我甚至要对这个正确的方式?

有帮助吗?

解决方案

我不知道这是否是理想的,但是这是我落得这样做:

$('input.ImageUpload').each(function() {
  $(this).uploadify({
    ...
    scriptData({'id': $(this).attr('id')},
    ...
  });
});

其他提示

这是我如何成功地使用它:

$(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 />
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top