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 回答