dshkmamau65777662
2013-03-27 16:50
浏览 31

在单个警报中显示来自多个文件输入的所有文件名

I have this function which checks if selected file names are already in the database. And it alerts a message stating which files are in the database. The problem is it's a multiple file input, so if there is more than 1 file name which is in the database, it will make a separate alert for each file name. how can I change this so it makes just 1 alert which lists all the filenames(preferably with a space or comma after each one)? Thanks

 var file = $('#file')[0];
 $.get('all_filenames.php', function(data){
       for (var i=0; i<file.files.length; i++) {
       var fname = file.files[i].name;
       if(~data.indexOf(fname)){

          alert("these files already exist:" + fname);
       }
    }
 },'json');

图片转代码服务由CSDN问答提供 功能建议

我有这个函数检查选定的文件名是否已经在数据库中。 它会警告一条消息,说明数据库中有哪些文件。 问题是它是一个多文件输入,因此如果数据库中有多个文件名,它将为每个文件名单独发出警报。 我怎样才能更改这个,所以只有1个警报,列出所有文件名(最好在每个文件名之后加上空格或逗号)? 谢谢

  var file = $('#file')[0]; 
 $ .get('all_filenames.php',function(data){
 for(  var i = 0; i&lt; file.files.length; i ++){
 var fname = file.files [i] .name; 
 if(~data.indexOf(fname)){
 
 alert(“ 这些文件已经存在:“+ fname); 
} 
} 
},'json'); 
   
 
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongyaxiao5884 2013-03-27 16:53
    已采纳

    Try this, I pushed the filenames to an array.

    JS

    var file = $('#file')[0];
    $.get('all_filenames.php', function (data) {
        var alreadyThere = [];
        for (var i = 0; i < file.files.length; i++) {
            var fname = file.files[i].name;
            if (~data.indexOf(fname)) {
                alreadyThere.push(fname);
            }
        }
        alert("These files already exist:" + alreadyThere.join(", ");
    }, 'json');
    
    打赏 评论

相关推荐 更多相似问题