这篇文章主要介绍js如何实现多文件上传,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!具体实现代码如下所示:<!DOCTYPE html> <html>
这篇文章主要介绍js如何实现多文件上传,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!
具体实现代码如下所示:
<!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">
<h2 >多文件上传 </h2>
<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如何实现多文件上传”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注编程网JavaScript频道!
--结束END--
本文标题: JS如何实现多文件上传
本文链接: https://www.lsjlt.com/news/74089.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-01-12
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0