js多图上传展示和删除
html部分
<button class="btn btn-info" for="file">请选择文件</button>
<input type="file" id="file" name="file" multiple='multiple' class="hidden" onchange="showPicture(this)"/>
<div id="imgBox" class="form-group">
js部分
var imgSrc = []; //图片路径
var imgFile = []; //文件流
var imgName = []; //图片名字
var imgBox=$('#imgBox');
function showPicture(imgF){
var fileList=imgF.files;
for(var i = 0; i < fileList.length; i++){
var imgSrcI = getObjectURL(fileList[i]);
imgName.push(fileList[i].name);
imgSrc.push(imgSrcI);
imgFile.push(fileList[i]);
}
addNewContent(imgBox);
}
//图片展示
function addNewContent(obj) {
$(imgBox).html("");
for(var a = 0; a < imgSrc.length; a++) {
//console.log(imgSrc);
var oldBox = $(obj).html();
$(obj).html(oldBox + '<div class="imgContainer col-sm-4"><img width="100%" class="img-rounded" title=' + imgName[a] + ' alt=' + imgName[a] + ' src=' + imgSrc[a] + ' ><span onclick="sc('+a+')">删除</span></div>');
}
}
//图片预览路径
function getObjectURL(file) {
var url = null;
if(window.createObjectURL != undefined) { // basic
url = window.createObjectURL(file);
} else if(window.URL != undefined) { // mozilla(firefox)
url = window.URL.createObjectURL(file);
} else if(window.webkitURL != undefined) { // webkit or chrome
url = window.webkitURL.createObjectURL(file);
}
return url;
}
//删除
function sc(index){ imgSrc.splice(index,1);
index='';
addNewContent(imgBox); }
效果如下

js多图上传展示和删除的更多相关文章
- js 移动端 多图上传 预览 删除 base64转为url 传给后端
说下主要的逻辑,首先是利用input type="file",上传文件,然后判断文件类型是否是图片,这里要注意(multiple,安卓一次一张,ios可以多张). 接着把本地图片转 ...
- jquery input file 多图上传,单张删除,查看
<div class="form-group"> <label for="imgs" class="col-md-3 col-sm- ...
- [PHP] layui实现多图上传,图片自由排序,自由删除
实现效果如下图所示: 实现代码: css代码 <style> .layui-upload-img { width: 90px; height: 90px; margin: ; } .pic ...
- 多图上传控制器及模型代码(2)thinkphp5+layui实现多图上传保存到数据库,可以实现图片自由排序,自由删除。
公共css代码 <style> .layui-upload-img { width: 90px; height: 90px; margin: 0; } .pic-more { width: ...
- thinkphp+layui多图上传(1)thinkphp5+layui实现多图上传保存到数据库,可以实现图片自由排序,自由删除。
公共css代码 <style> .layui-upload-img { width: 90px; height: 90px; margin: 0; } .pic-more { width: ...
- layui多图上传
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- thinkphp5多图上传 js部分
在项目中常会用到多图上上传,那就需要多图上传后需要预览,并且能删掉传错(不想传)的图,然而 测试了半天 并不知道jq怎么写,parent()parents()用了半天无果,罢了,还是用原生js来写.这 ...
- js formData图片上传(单图上传、多图上传)后台java
单图上传 <div class="imgUp"> <label>头像单图</label> <input type=&quo ...
- js将用户上传gif动图分解成多张帧图片
js将用户上传gif动图分解成多张帧图片 写在前面 工作中遇到一个这么一个需求:这是一个多图上传的场景,如果用户上传选择多张图片,则上传后直接展示多张图片,如果上传的图片是gif动图,则需要分解这张动 ...
随机推荐
- mysql视图详解
什么是视图 视图是从一个或多个表中导出来的表,是一种虚拟存在的表. 视图就像一个窗口,通过这个窗口可以看到系统专门提供的数据. 这样,用户可以不用看到整个数据库中的数据,而之关心对自己有用的数据. ...
- Vue 获取dom元素之 ref 和 $refs 详解
一.$refs 一个对象,持有ref注册过的所有元素或子组件.(注册过的 ref 的集合) 二.ref 被用来给元素或子组件注册引用信息.若用在dom元素上,引用指向的就是dom元素:若用在子组件上, ...
- Dock镜像初探索
一.安装CentOS版DockerCE 1.1 卸载旧的版本 yum remove docker \ docker-client \ docker-client-latest \ docker-com ...
- Object上的静态方法
内置提供了一个对象为 Object ,也被称之为是构造函数,用来创建对象用的.在 javascript 函数也是对象,是一种可被执行的对象,所以称Object为对象也是可以的.挂在函数上的方法,称之为 ...
- c++ 链接mysql:error LNK2019: 无法解析的外部符号
使用VS2012编译项目报错如下: error LNK2019: 无法解析的外部符号 _mysql_real_connect@32,该符号在函数 _main 中被引用 error LNK2019: 无 ...
- mybatis学习:mybatis的注解开发CRUD操作
Dao层: public interface IUserDao { /** * 查询所有结果 * @return */ @Select("select * from user") ...
- UVA11916 Emoogle Grid
Emoogle Grid You have to color an M × N (1 ≤ M, N ≤ 108 ) two dimensional grid. You will be provided ...
- 设置mysql二进制日志过期时间
((none)) > show variables like 'expire_logs_days'; +------------------+-------+ | Variable_name | ...
- 链接的属性href=“?” ?该些什么及优缺点
<a onclick="{jscode}">是很常见的一种js运用方式,使用时经常会加一个href=“###”即<a onclick="{jscode} ...
- Codeforces 608E. Marbles
E. Marbles time limit per test 2 seconds memory limit per test 256 megabytes input standard input ou ...