<div class="div-title">
<h5>图片上传</h5>
<div class="photo-box">
<div class="photo-box-icon">
<img style="width: 100%;" src="<%=staticServPath%>/static/img/H5_addPhoto.png" alt="picture">
<input type="file" onchange="angular.element(this).scope().addPhoto(this)" accept="image/*" id="carPhotoFile" />
</div>
</div>
</div>
/*图片上传*/
.photo - box {
padding: 10 px;
display: inline - block;
}
.photo - box - icon {
width: 50 px;
height: 50 px;
display: inline - block;
position: relative;
}
.photo - box - icon img {
width: 100 % ;
height: 100 % ;
}
.photo - box - icon input {
width: 50 px;
height: 50 px;
position: absolute;
top:;
opacity:;
}
.photo - add {
width: 230 px;
height: 100 px;
display: inline - block;
margin - right: 10 px;
margin - bottom: 10 px;
border: 1 px solid #32c5d2;
position: relative;
z-index:;
}
.photo-add img{
width: 100%;
height: 100%;
background-size: 100% 100%;
}
.photo-add .closeIcon{
position: absolute;
top:;
background: red;
height: 20px;
width: 100%;
display: none;
}
.photo-add .closeIcon .delPhoto-btn{
position: absolute;
right:;
width: 20px;
height: 18px;
top: 1px;
text-align: center;
cursor: pointer;
}
$scope.addPhoto = function(file) {
var fileObj = file.files[0];
var formData = new FormData();
formData.append('file', fileObj);
var options = {
url: webroot + "/services/api/file/uploadImg",
type: 'POST',
data: formData,
processData: false,
contentType: false,
headers: {
'ticket': ticket
},
success: function(rsp) {
if (rsp.code == 200) {
imgs = rsp.result;
var innerHtml = '<div class="photo-add" onchange="angular.element(this).scope().showPhoto(this)">' +
'<img style = "width: 100%;" src="' + imgs + '" alt = "添加照片" class="photoShow" />' +
'</div>';
$(".photo-box").before(innerHtml);
attachmentArr.push(rsp.result);
} else {
console.log(rsp.message);
}
},
error: function(e) {
console.log("网络错误!");
}
};
$.ajax(options);
};
var attachmentArr = [];

function addPhoto(file) {
var fileObj = file.files[0];
var formData = new FormData();
formData.append('file', fileObj);
var options = {
url: webroot + "/upload/uploadImg",
type: 'POST',
data: formData,
processData: false,
contentType: false,
success: function(rsp) {
if (rsp.code == 200) {
imgs = rsp.result;
var innerHtml = '<div class="photo-add" onmouseover ="IconShow(this)" onmouseout ="IconHide(this)">' +
'<img style = "width: 100%;" src="' + imgs + '" alt = "添加照片" class="photoShow" />' +
'<div class="closeIcon">' +
'<span class="delPhoto-btn" onclick="delPhoto(this)">' + "X" +
'</span>' +
'</div>' +
'</div>';
$(".photo-box").before(innerHtml);
attachmentArr.push(rsp.result);
// 超过两张图片隐藏图标
// if (attachmentArr.length >= 2) {
// $('.photo-box-icon').hide();
// };
} else {
hint(rsp.message);
}
},
error: function(e) {
console.log("网络错误!");
}
};
$.ajax(options);
};
//删除图标显隐
function IconShow(e) {
$(e).children('.closeIcon').show();
}; function IconHide(e) {
$(e).children('.closeIcon').hide();
};
//图片删除
function delPhoto(e) {
var thisImage = $(e).parent().parent().find('img').attr("src");
attachmentArr.remove(thisImage);
$(e).parent().parent().remove();
};

input file图片上传的更多相关文章

  1. input file 图片上传

    使用第三方:jquery.ajaxfileupload.jsinput中的name根据后端来定 <form method="post" enctype="multi ...

  2. form input file 图片上传360IE兼容问题

    <form action="" class="form-box" class="form_box" enctype="mul ...

  3. input file图片上传预览

    两种方法,方法一: js代码: //头像上传预览 $("#up").change(function() { var $file = $(this); var fileObj = $ ...

  4. input file图片上传预览效果

    两种方法,方法一: js代码: //头像上传预览 $("#up").change(function() { var $file = $(this); var fileObj = $ ...

  5. input file 图片上传展示重新上传

    html <div> <label class="imgMark">说明:</label> <div class="erWeiM ...

  6. js 实现 input file 文件上传

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat=&qu ...

  7. input file 文件上传标签的样式美化

    input file 文件上传标签的样式美化 将<input type="file">的透明度设置为0: <input type="file" ...

  8. PHP 多input file文件上传

    前台html jquery代码 后台PHP处理 前台html <form id="form" method="post" enctype="mu ...

  9. file图片上传之前先预览

    链接:https://www.cnblogs.com/tandaxia/p/5125275.html 记得以前做网站时,曾经需要实现一个图片上传到服务器前,先预览的功能.当时用html的<inp ...

随机推荐

  1. Javascript高级编程学习笔记(42)—— DOM(8)Attr类型

    Attr类型 我们在之前的文章中提到了,元素有一个 attributes 属性 该属性保存了一个 NamedNodeMap 集合 该集合中的元素也就是今天我们所要记叙的 attr 类型 主要就是方便我 ...

  2. db2 报错 sqlcode=-420 自动类型转换的问题

    今天在测试遇到一个问题,前台点击页面查询数据时报错: , SQLSTATE, SQLERRMC=DECFLOAT, DRIVER=4.18.60 根据sqlcode查询错误原因为:-420 22018 ...

  3. DCT(离散余弦变换)算法原理和源码(python)

    原理: 离散余弦变换(DCT for Discrete Cosine Transform)是与傅里叶变换相关的一种变换,它类似于离散傅里叶变换(DFT for Discrete Fourier Tra ...

  4. 利用 Linux tap/tun 虚拟设备写一个 ICMP echo 程序

    本文首发于我的公众号 Linux云计算网络(id: cloud_dev),专注于干货分享,号内有 10T 书籍和视频资源,后台回复「1024」即可领取,欢迎大家关注,二维码文末可以扫. 前面两篇文章已 ...

  5. kafka和storm集群的环境安装

    前言 storm和kafka集群安装是没有必然联系的,我将这两个写在一起,是因为他们都是由zookeeper进行管理的,也都依赖于JDK的环境,为了不重复再写一遍配置,所以我将这两个写在一起.若只需一 ...

  6. leetcode — first-missing-positive

    /** * * Source : https://oj.leetcode.com/problems/first-missing-positive/ * * Created by lverpeng on ...

  7. 逆向知识第一讲,IDA的熟悉使用

    逆向知识第一讲,IDA的熟悉使用 一丶熟悉IDA,以及手工制作sig文件. IDA,静态分析工具,网上随便找一个即可下载. 首先,我们写一个可执行EXE,最简单的 使用IDA打开. 1.提示使用什么格 ...

  8. 【原创】uC/OS 中LES BX,DWORD PTR DS:_OSTCBCur的作用及原理

    LES BX, DWORD PTR DS:_OSTCBCur ;OSTCBCur->OSTCBStkPtr = SS:SP!!! ], SS ;将当前SS(栈的基地址)寄存器值存放至当前任务控制 ...

  9. ES6躬行记(11)——对象

    在第5篇中,讲解了多个对象字面量的改进,本节将重点介绍两个新增的静态方法,以及对象属性的重复处理和枚举顺序. 一.Object.is() 此方法用于判断两个值是否相同,内部实现了SameValue算法 ...

  10. Flask入门第二天

    一.请求钩子 在客户端和服务器交互的过程中,有些准备工作或稍微工作是需要处理的,比如:在请求开始时,建立数据库连接:在请求开始时,根据需求进行权限校验:在请求结束时,指定数据的交互格式等.为了让每个视 ...