<tr>
<td class="listtitle-up">尿素箱</td>
<td>
<div class="comtainerimg upimg-div floatleft">
<input type="hidden" value="" id="photo-4" name=""/>
</div>
<div class="z_photo floatleft" >
<section class="z_file fl">
<img src="mrm/css/bigimg/a11.png" class="add-img">
<input type="file" name="file" id="file4" class="file" value="" accept="image/jpg,image/jpeg,image/png,image/bmp,image/PNG" multiple style="opacity: 0"/>
</section>
</div>
<a class="removelist" href="javascript:">
<i class="fa fa-trash-o" ></i>
<a>
</td>
</tr> <aside class="mask works-mask" style="display: none;">
<div class="mask-content">
<h3>删除图片</h3>
<p class="del-p">您确定要删除吗?</p>
<p class="check-p"><span class="del-com wsdel-ok"><i class="glyphicon glyphicon-ok"></i> 确定</span><span class="wsdel-no"><i class="glyphicon glyphicon-remove"></i>取消</span></p>
</div>
</aside>
$(function(){
var delParent;
var defaults = {
fileType : ["jpg","png","bmp","jpeg","PNG"], // 上传文件的类型
fileSize : 1024 * 1024 * 10 // 上传文件的大小 10M
};
/*点击图片的文本框*/
var j=0;
$(document).on('change','.file',function(){ var imgsrc= "";//声明图片的路径
var creatarry=new Array();
// $(".file").change(function(){alert("1");
var idFile = $(this).attr("id");
var file = document.getElementById(idFile);
var imgContainer = $(this).parents(".z_photo").siblings('.comtainerimg'); //存放图片的父亲元素
var fileList = file.files; //获取的图片文件
console.log(fileList+"======filelist=====");
var input = $(this).parent();//文本框的父亲元素
var imgArr = [];
//遍历得到的图片文件
var numUp = imgContainer.find(".up-section").length;
var totalNum = numUp + fileList.length; //总的数量
// 声明新input
var newinput="<input type='file' name='file' id='newfile' class='file' value='' accept='image/jpg,image/jpeg,image/png,image/bmp,image/PNG' multiple style='opacity: 0'/>";
// if(fileList.length > 5 || totalNum > 5 ){
// alert("上传图片数目不可以超过5个,请重新选择"); //一次选择上传超过5个 或者是已经上传和这次上传的到的总数也不可以超过5个
// }
// else if(numUp < 5){
fileList = validateUp(fileList); for(var i = 0;i<fileList.length;i++){
var imgUrl = window.URL.createObjectURL(fileList[i]);
imgArr.push(imgUrl);
var $section = $("<section class='up-section fl loading'>");
imgContainer.append($section);
var $span = $("<span class='up-span'>");
$span.html(fileList[i].name).appendTo($section); var $img0 = $("<img class='close-upimg' src='/hvdm/r/mrm/css/bigimg/a7.png'>").on("click",function(event){
event.preventDefault();
event.stopPropagation();
$(".works-mask").show();
delParent = $(this).parent();
});
$img0.appendTo($section);
var $a = $("<a rel='lightbox-group'>");
$a.attr("href",imgArr[i]);
var $img = $("<img class='up-img up-opcity'>");
$img.attr("src",imgArr[i]);
$img.appendTo($a);
$a.appendTo($section);
var $p = $("<p class='img-name-p'>");
$p.html(fileList[i].name).appendTo($section);
var $input = $("<input id='taglocation' name='taglocation' value='' type='hidden'>");
$input.appendTo($section);
var $input2 = $("<input id='tags' name='tags' value='' type='hidden'/>");
$input2.appendTo($section); // imgsrc+=imgArr[i]+",";//循环 累加href值
imgsrc+=imgArr[i];//循环 累加href值
creatarry.push(imgArr[i]);//将href各个 值存入到数组中 }
var srcval=imgContainer.find("section").siblings('input').val(); //第二次点击添加图片 之前的href链接地址;
if(srcval){//如果有地址 说明是第二次点击效果;
var oldsrc=srcval.split(";"); //将之前存入的 链接 转为数组
oldsrc.concat(creatarry); //并拼接 现在上传点击的图片链接
imgContainer.find("section").siblings('input').val(oldsrc.concat(creatarry).join(';'));//并赋给 input值
setTimeout(function(){ //执行加载效果,结束事件
$(".up-section").removeClass("loading");
$(".up-img").removeClass("up-opcity");
},450);
// console.log($('.file').val());$('.file').val(''); $(this).hide();
console.log($(this).val());
$(this).parents('.z_file').append("<input type='file' name='file' id='newfile" + j + "' class='file' value='' accept='image/jpg,image/jpeg,image/png,image/bmp,image/PNG' multiple style='opacity: 0'/>");
j=j+1;
return false;
}
imgContainer.find("section").siblings('input').val(creatarry.join(';')+";"+imgContainer.parents("tr").find(".listtitle-up").html());//给隐藏域追加所有href值
if(srcval){alert("0");
var newvalue=imgContainer.find("section").siblings('input').val(creatarry.join(';')+";"+imgContainer.parents("tr").find(".listtitle-up").html());
alert("1");
imgContainer.find("section").siblings('input').val(newvalue);
}
// }
setTimeout(function(){
$(".up-section").removeClass("loading");
$(".up-img").removeClass("up-opcity");
},450);
numUp = imgContainer.find(".up-section").length;
if(numUp >= 5){
// $(this).parent().hide();
} //input内容清空
// $(this).val("");
//限制字符个数
$(".up-span").each(function() {
var maxwidth = 6;
if ($(this).text().length > maxwidth) {
$(this).text($(this).text().substring(0, maxwidth));
$(this).html($(this).html() + '...');
}
}); $(this).hide();
console.log($(this).val());
$(this).parents('.z_file').append("<input type='file' name='file' id='newfile" + j + "' class='file' value='' accept='image/jpg,image/jpeg,image/png,image/bmp,image/PNG' multiple style='opacity: 0'/>");
j=j+1;
console.log(j); }); $(".z_photo").delegate(".close-upimg","click",function(){
$(".works-mask").show();
delParent = $(this).parent();
imgsrcs=$(this).parents("section").siblings('input');
}); $(".wsdel-ok").click(function(){
$(".works-mask").hide();
var numUp = delParent.siblings().length;
// var srcall=imgsrcs.val();
if(numUp < 6){
delParent.parent().find(".z_file").show();
}
var srcinput=delParent.siblings('input');//声明 被删除的 行中的隐藏input
var srcall=delParent.siblings('input').val();//声明input的值
var srcallarry=srcall.split(';');//将input的val值转为数组
var thissrc=delParent.find('a').attr('href'); //查找要删除的图片链接值
delParent.remove(); //移除 section 标签域
// var nullarry=new Array();//声明空 数组
for(var j=0;j<=srcallarry.length;j++){//循环 input中 的val值 ,除需要删除的链接值
if(srcallarry[j]==thissrc){
srcallarry.splice(j,1);
j=j-1;
// nullarry.push(srcallarry[j]);//将除删除连接的值存入空数组
}
}
srcinput.val(srcallarry.join(';'));//新数组的值 赋给input
if(numUp==1){
srcinput.val('');
} }); $(".wsdel-no").click(function(){
$(".works-mask").hide();
}); function validateUp(files){
var arrFiles = [];//替换的文件数组
for(var i = 0, file; file = files[i]; i++){
//获取文件上传的后缀名
var newStr = file.name.split("").reverse().join("");
if(newStr.split(".")[0] != null){
var type = newStr.split(".")[0].split("").reverse().join("");
console.log(type+"===type===");
if(jQuery.inArray(type, defaults.fileType) > -1){
// 类型符合,可以上传
if (file.size >= defaults.fileSize) {
alert(file.size);
alert('您这个"'+ file.name +'"文件大小过大');
} else {
// 在这里需要判断当前所有文件中
arrFiles.push(file);
}
}else{
alert('您这个"'+ file.name +'"上传类型不符合');
}
}else{
alert('您这个"'+ file.name +'"没有类型, 无法识别');
}
}
return arrFiles;
} })

 

上传多张图片imgupload的更多相关文章

  1. iOS -- 上传多张图片 后台(PHP)代码和上传一张的一样

    // 上传多张图片 - (void)send { // 设置初始记录量为0 self.count = 0; self.upcount = 0; // 设置初始值为NO self.isUploadPic ...

  2. php用jquery-ajax上传多张图片限制图片大小

    php用jquery-ajax上传多张图片限制图片大小 /** * 上传图片,默认大小限制为3M * @param String $fileInputName * @param number $siz ...

  3. 微信JSSDK上传多张图片

    之前是使用for循环实现的,但是安卓手机没有问题,苹果手机只能上传最后一张图片. 好在有高手在前面趟路,实用的循环调用.苹果是没有,安卓不清楚.以下内容转自:http://leo108.com/pid ...

  4. 整理几个js上传多张图片的效果

    一.普通的上传图片,张数不限制 <!DOCTYPE HTML> <html> <head> <meta charset="UTF-8"&g ...

  5. 如何在IPFS里面上传一张图片

    之前有好几人问过小编,想在IPFS里面上传一张图片.如何做? 今天小编就讲一下如何在IPFS里面上传.下载文件? 1 下载IPFS软件 下载地址:https://dist.ipfs.io/#go-ip ...

  6. Ajax+PHP实现异步上传多张图片

    Ajax+PHP实现异步上传多张图片 HTML代码 <!-- date: 2018-04-27 13:46:55 author: 王召波 descride: 多张图片上传 --> < ...

  7. 1) 上传多张图片时 ,对 $_FILES 的处理. upload ; 2)fileinput 上传多张图片. 3) 修改,删除的时候删除原来的资源,图片 update, delete , 删除 4)生成器中两个字段上传图片的时候,要修改生成器生成的代码

    1上传多张图片, 要对 $_FILES进行 重新处理. //添加 public function addCourseAlbumAction() { $CourseAlbumModel = new Co ...

  8. Okhttp3上传多张图片同时传递参数

    之前上传图片都是直接将图片转化为io流传给服务器,没有用框架传图片. 最近做项目,打算换个方法上传图片. Android发展到现在,Okhttp显得越来越重要,所以,这次我选择用Okhttp上传图片. ...

  9. POST请求上传多张图片并携带参数

    POST请求上传多张图片并携带参数 在iOS中,用POST请求携带参数上传图片是非常恶心的事情,HTTPBody部分完全需要我们自己来配置,这个HTTPBody分为3个部分,头部分可以携带参数,中间部 ...

随机推荐

  1. dorado7-发布

    1.首先将configure.properties中Debug删除 2.eclipse自带的打包方式进行打包 2.1 next==>选择打包文件存放的路径==>finish==>xx ...

  2. MySQL事务一致性理解

    一致性是指数据处于一种语义上的有意义且正确的状态.一致性是对数据可见性的约束,保证在一个事务中的多次操作的数据中间状态对其他事务不可见的.因为这些中间状态,是一个过渡状态,与事务的开始状态和事务的结束 ...

  3. openvswitch BFD 简介

    为了保护关键应用,网络中会设计有一定的冗余备份链路,网络发生故障时就要求网络设备能够快速检测出故障并将流量切换至备份链路以加快网络收敛速度.目前有些链路(如POS)通过硬件检测机制来实现快速故障检测. ...

  4. 程序媛计划——mysql 插入、查找、修改、删除数据

    #插入.查找数据 [mysql>create table if not exists exam_score( ..>id int(4) not null primary key auto_ ...

  5. FFmpeg软硬解和多线程解码

    一. AVCodecContext解码上下文 1.avcodec_register_all() : 注册所有的解码器 2.AVCodec *avcodec_find_decoder(enum AVCo ...

  6. Educational Codeforces Round 25 C. Multi-judge Solving

    题目链接:http://codeforces.com/contest/825/problem/C C. Multi-judge Solving time limit per test 1 second ...

  7. SAX,功能强大的 API

    https://www.ibm.com/developerworks/cn/xml/x-saxapi/ SAX,功能强大的 API 在摘自 XML by Example 的本篇预览中比较了 DOM 和 ...

  8. webpack快速入门——打包后如何调试

    在配置devtool时,webpack给我们提供了四种选项. source-map:在一个单独文件中产生一个完整且功能完全的文件.这个文件具有最好的source map,但是它会减慢打包速度: che ...

  9. mysql编写存储过程(2)

    书接上回. 实例8:if-then -else语句 实例9:case语句: 实例10:循环语句,while ···· end while: 实例11:循环语句,repeat···· end repea ...

  10. 《JAVA与模式》之适配器模式

    在阎宏博士的<JAVA与模式>一书中开头是这样描述适配器(Adapter)模式的: 适配器模式把一个类的接口变换成客户端所期待的另一种接口,从而使原本因接口不匹配而无法在一起工作的两个类能 ...