drqrdkfue521903877 2012-04-04 17:31
浏览 92
已采纳

javascript函数只提供第一个FileUpload的文件大小,而不提供其他文件大小

I am making file input boxes through a javascrpit function, if the user wants to Attach more files, The function is

<script type="text/javascript">
var upload_number = 1;
var attachmentlimit = 5;
function addFileInput() {

var d = document.createElement("div");
var file = document.createElement("input");
file.setAttribute("type", "file");
file.setAttribute("name", "attach[]");
d.appendChild(file);
document.getElementById("moreUploads").appendChild(d);
upload_number++;
if(upload_number == attachmentlimit) {
      document.getElementById('moreUploadsLink').style.display='none';
    }

    }
    </script>

I am also checking the size of the File input at client through javascript function,

  <script type="text/javascript">
  var myFile = document.getElementById('attach');
    myFile.addEventListener('change', function() {
   var  size = this.files[0].size;
   alert(size,'File Size Exceeds'); 
   });
  </script>

The problem is, the above javascript function, gives the Size alert of only the first File Upload box, and not the others. Any one who tell how to make this to provide sizes of all file uploads.

  • 写回答

1条回答 默认 最新

  • doumen6605 2012-04-04 17:35
    关注

    Add the event listener to the file somewhere around d.appendChild(file). Otherwise, if you never tell JS to listen for the event, how can you expect it to?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制