SoFunction
Updated on 2025-04-06

JS multi-file upload instance code

I won't say much nonsense, the specific implementation code is as follows:

<!DOCTYPE html>
<html>
<head lang="en">
 <meta charset="UTF-8">
 <title></title>
 <script src="./jquery-1.9."></script>
</head>
<body>
<form id= "uploadForm" action= "" method= "post" enctype ="multipart/form-data">
 <h1 >Multiple file uploads </h1>
 <table>
  <tr>
   <td >Upload file: <input type ="file" name="file[]"  multiple="multiple"/><a href="javascript:;" >[+]</a></td>
  </tr>
  <tr>
   <td>
    <input type ="button" value="Upload" />
   </td>
  </tr>
 </table>
</form>
</body>
</html>
<script>
 //Add to $(document).on("click","#add",function(){
  var str_tr = "<tr>"+$(this).parents("tr").html()+"</tr>";
  //js replace string style  str_tr = str_tr.replace(/\+/,'-');
  var new_str_tr = str_tr.replace(/add/,'del');
  $(this).parents("tr").after(new_str_tr);
 })
 //delete $(document).on("click","#del",function(){
  $(this).parents("tr").remove();
 })
 //Upload file $("#but").click(function(){
  var formData = new FormData($( "#uploadForm" )[0]);
  $.ajax({
   url: 'http://localhost/demo/selfWork_MVC/easymvc/app/Views/Index/' ,
   type: 'POST',
   data: formData,
   async: false,
   cache: false,
   contentType: false,
   processData: false,
   success: function (returndata) {
    alert(returndata);
   },
   error: function (returndata) {
    alert(returndata);
   }
  });
 })
</script>

Related reference:

Native JavaScript implements asynchronous multi-file upload

js implementation input type="file" file upload sample code

The above is the example code for uploading JS multi-files introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to everyone in time. Thank you very much for your support for my website!