0

ファイルがタグに追加されるとすぐにタグを検証するために、以下のスクリプトを作成しました。このタグのIDは「#audiofile」です。複数の入力フィールド (#audiofile1、#audiofile2、#audiofile3) を用意する予定ですが、このスクリプトを 10 回繰り返して 10 個のファイルをチェックする必要はありません。これを for ループの中に入れて、すべてのフィールドをチェックするにはどうすればよいですか?

$('#audiofile').bind('change', function() {

if (this.files[0].type != 'image/png') {
  $('#audiofile').each(function(){
  $(this).after($(this).clone(true)).remove();
});

$('#message').html('Invalid file type'); 
alert(this.files[0].name + ' is not a valid file type. MP3 Format only.');

} else {  

  if (this.files[0].size > '5000') {

    $('#audiofile').each(function() {
      $(this).after($(this).clone(true)).remove();
    });

    $('#message').html('To Large');  
    alert(this.files[0].name + ' exceeds the maximuim file size.');
  } else {
     $("#audiofile").fadeTo(1500, 0.20);
    $('#message').html('Added');
    alert(this.files[0].name + ' was added successfuly.');
  }
}
});
4

1 に答える 1

0

各入力フィールドにクラスを追加し、各ループでjqueryを使用します。

各説明

$("input.fileclass").each(function( index ){
          $(this)....//reference to input box
});
于 2013-01-18T06:47:01.457 に答える