<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. Java 11 究竟比 8 快了多少?

    阅读本文大概需要 1.2 分钟. 作者:h4cd 来源:开源中国社区 开源规划调度引擎 OptaPlanner 官网发布了一个 Java 11 GC 性能基准测试报告. 当前使用量最大的 Java 版 ...

  2. navicat连接mysql报错1251的解决方法

    1.新安装的mysql8,使用破解版的navicat连接的时候一直报错,如图所示: 2.网上查找原因发现是mysql8 之前的版本中加密规则是mysql_native_password,而在mysql ...

  3. MySQL数据库的锁机制

    在并发访问情况下,很有可能出现不可重复读等等读现象.为了更好的应对高并发,封锁.时间戳.乐观并发控制(乐观锁).悲观并发控制(悲观锁)都是并发控制采用的主要技术方式. 锁分类 ①.按操作划分:DML锁 ...

  4. python 安装 reportlab 报错 “ImportError: No module named reportlab.lib”

    reportlab是什么? 是一个处理PDF和画图的python开源库. 初次安装: pip install reportlab 重新安装: pip install --upgrade --force ...

  5. Python 高度定制化自己的线程类和进程类代码,获取启动进程或线程方法的结果(兼容Py2和Py3)

    #encoding=utf-8 from threading import Thread from multiprocessing import Process import multiprocess ...

  6. multiprocessing- 基于进程的并行性

    介绍 multiprocessing是一个使用类似于threading模块的API支持生成进程的包.该multiprocessing软件包提供本地和远程并发,通过使用子进程而不是线程有效地支持 全局解 ...

  7. ionic3 ionic serve build fail Error: webpackJsonP is not defined

    ionic升级后发现 ionic serve 跑起来项目出现一下错误: Runtime Error: webpackJsonP is not definedStack: @http://localho ...

  8. leetcode — sqrtx

    /** * Source : https://oj.leetcode.com/problems/sqrtx/ * * * Implement int sqrt(int x). * * Compute ...

  9. es6入门1-- let与var的区别详解

    一.前言 说到做到,现在暂时放了放JS模式的读书笔记,打算好好看看ES6,毕竟出了这么久了,还是靠JS吃饭的,都不好好学JS新特性,确实说不过去,我本来是想当读书笔记去记录ES6,但是这个确实是属于边 ...

  10. SpringBoot(5) SpringBoot个性化启动

    1.在类路径下增加一个banner.txt,里面是启动要输出的信息 自定义banner在线生成工具: http://www.bootschool.net/ascii _ _ _ _ __ | | __ ...