欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

JS多文件上傳的實例代碼

 更新時間:2017年01月11日 08:55:43   作者:index_ling  
本文通過實例代碼給大介紹了js多文件上傳的實現(xiàn)方法,非常不錯,具有參考借鑒價值,需要的朋友參考下

廢話不多說了,具體實現(xiàn)代碼如下所示:

<!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>

相關(guān)參考:

原生JavaScript實現(xiàn)異步多文件上傳

js 實現(xiàn) input type="file" 文件上傳示例代碼

以上所述是小編給大家介紹的JS多文件上傳的實例代碼,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評論