可预览删除的jQuery多图上传ajax提交

来源:https://www.sucaihuo.com/js/3121.html 2017-09-30 22:35浏览(2974) 收藏

一款可预览删除的jQuery多图上传ajax提交的代码,点击按钮来选择图片,可以选择多张图片,选择好的图片立即显示在按钮下面,鼠标悬停在预览的图片时,出现“删除”字样的按钮,点击即可删除图片,点击上传后,可以打开控制台查看上传的参数。
可预览删除的jQuery多图上传ajax提交
分类:html5 > 上传 难易:初级
查看演示 下载资源 下载积分: 20 积分

页面的head部分,需设置好页面的样式并引入jQuery文件,代码如下:

<style type="text/css">
*{
	margin: 0;
	padding: 0;
	font-family: 'Microsoft YaHei','Lantinghei SC','Open Sans',Arial,'Hiragino Sans GB','STHeiti','WenQuanYi Micro Hei','SimSun',sans-serif;
}
#upBox{
	text-align: center;
	width:500px;
	padding: 20px;
	border: 1px solid #666;
	margin: auto;
	margin-top: 150px;
	margin-bottom: 200px;
	position: relative;
	border-radius: 10px;
}
#inputBox{
	width: 100%;
	height: 40px;
	border: 1px solid cornflowerblue;
	color: cornflowerblue;
	border-radius: 20px;
	position: relative;
	text-align: center;
	line-height: 40px;
	overflow: hidden;
	font-size: 16px;
}
#inputBox input{
	width: 114%;
	height: 40px;
	opacity: 0;
	cursor: pointer;
	position: absolute;
	top: 0;
	left: -14%;
	
}
#imgBox{
	text-align: left;
}
.imgContainer{
	display: inline-block;
	width: 32%;
	height: 150px;
	margin-left: 1%;
	border: 1px solid #666666;
	position: relative;
	margin-top: 30px;
	box-sizing: border-box;
}
.imgContainer img{
	width: 100%;
	height: 150px;
	cursor: pointer;
}
.imgContainer p{
	position: absolute;
	bottom: -1px;
	left: 0;
	width: 100%;
	height: 30px;
	background: black;
	text-align: center;
	line-height: 30px;
	color: white;
	font-size: 16px;
	font-weight: bold;
	cursor: pointer;
	display: none;
}
.imgContainer:hover p{
	display: block;
}
#btn{
	outline: none;
	width: 100px;
	height: 30px;
	background: cornflowerblue;
	border: 1px solid cornflowerblue;
	color: white;
	cursor: pointer;
	margin-top: 30px;
	border-radius: 5px;
}
</style>
<script type="text/javascript" src="js/jquery.min.js"></script>

页面的body部分,在多个div嵌套结构里放入input file文件选择标签,代码如下:

<div style="width: 100%;height: 100vh;position: relative;">
	<div id="upBox">
	 <div id="inputBox"><input type="file" title="请选择图片" id="file" multiple accept="image/png,image/jpg,image/gif,image/JPEG"/>点击选择图片</div>
     <div id="imgBox">
     </div>
     <button id="btn">上传</button>
	</div>
</div>

页面的底部,需引入上传插件,并启用插件设置好相应参数,代码如下:

<script type="text/javascript" src="js/uploadImg.js" charset="utf-8"></script>
<script type="text/javascript">
imgUpload({
	inputId:'file', //input框id
	imgBox:'imgBox', //图片容器id
	buttonId:'btn', //提交按钮id
	upUrl:'',  //提交地址
	data:'file1' //参数名
})
</script>
评论0
头像

系统已开启自动识别垃圾评论机制,识别到的自动封号,下载出错或者资源有问题请联系全栈客服QQ 1915635791

1 2