廢話不多說了,具體實現代碼如下所示:
<!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8"> <title></title> <script src="./jquery-1.9.1.min.js"></script></head><body><form id= "uploadForm" action= "" method= "post" enctype ="multipart/form-data"> <h1 >多文件上傳 </h1> <table> <tr> <td >上傳文件: <input type ="file" name="file[]" id="file" multiple="multiple"/><a href="javascript:;" id="add">[+]</a></td> </tr> <tr> <td> <input type ="button" value="上傳" id="but"/> </td> </tr> </table></form></body></html><script> //添加 $(document).on("click","#add",function(){ var str_tr = "<tr>"+$(this).parents("tr").html()+"</tr>"; //js 替換字符串樣式 str_tr = str_tr.replace(//+/,'-'); var new_str_tr = str_tr.replace(/add/,'del'); $(this).parents("tr").after(new_str_tr); }) //刪除 $(document).on("click","#del",function(){ $(this).parents("tr").remove(); }) //文件上傳 $("#but").click(function(){ var formData = new FormData($( "#uploadForm" )[0]); $.ajax({ url: 'http://localhost/demo/selfWork_MVC/easymvc/app/Views/Index/upload.php' , type: 'POST', data: formData, async: false, cache: false, contentType: false, processData: false, success: function (returndata) { alert(returndata); }, error: function (returndata) { alert(returndata); } }); })</script>相關參考:
js 實現 input type="file" 文件上傳示例代碼
以上所述是小編給大家介紹的JS多文件上傳的實例代碼,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對武林網網站的支持!
新聞熱點
疑難解答