質問

私はJavaScriptとjQueryのにはかなり新しいです。私は、サーバーに画像をアップロードするUploadifyを使用しています。ページに複数のアップローダのオブジェクトがあります。私は、サーバーに使用されているアップローダオブジェクトのIDを渡す必要があります。これは私がこれまで持っているものです。

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

どのように私はこれを実現することができますか?私は "this.id" と "$(この).ATTR( 'IDを')" しようとしました。私も正しい方法でこれについて行くだろうか?

役に立ちましたか?

解決

これが理想的である場合は、

私はわからないんだけど、これは私がやってしまったものです。

$('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