<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. CCS3怎么实现border边框渐变效果

    下图注册按钮的边框有渐变效果,如果让你来实现,你会怎么做呢 个人觉得,省事的做法,直接让UI给背景图片就可以了,如下图 不过这种做法感觉不太灵活,如果要修改border的渐变颜色,就需要UI重新做图. ...

  2. mysql怎么限制ip访问

    grant all privileges on *.* to 'root'@'ip'identified by '密码'; #授权某个ip的用户可以通过密码访问数据库

  3. JSP中的作用域

    application用于全局变量,可以获取全局的数据.作用范围比session大. JSP常用内置对象总结:out对象:用于客户端输出数据.request对象:用于处理客户端发送的请求的数据信息.r ...

  4. HBase之HRegionServer启动(含与HMaster交互)

    在我的博文<HBase——HMaster启动之一>.<HBase——HMaster启动之二>中已经详细介绍过HMaster在启动过程中调用的各种方法.下面,单就HRegionS ...

  5. 浅谈工作单元 在整个 ABP 框架当中的应用

    ABP在其内部实现了工作单元模式,统一地进行事务与连接管理. 其核心就是通过 Castle 的 Dynamic Proxy 进行动态代理,在组件注册的时候进行拦截器注入,拦截到实现了 Unit Of ...

  6. HW2018校招软件类笔试题

    一. 1.题目 输入一个字符串,输出字符串中最长的数字串.如果有多个数字串长度相等且都是最长的,则按照字符串顺序输出最后一个最长的数字串. 2.解答 [code] import java.util.* ...

  7. flex布局常见用法小结

    1,display:flex 这个在父容器中声明: 2,flex-direction:row / column 默认为横向,也在父容器中设置,定义flex布局的主轴方向:一条轴为主轴,那么另一条轴自然 ...

  8. 解决AssetBundle包加载预制体时,Shader显示异常的问题

    现象: 预制体上的粒子效果显示为紫色方块. 原因:shader在打成AB包后与指定平台产生相关性,Editor中无法正常读取. 解决办法: 遍历所有加载的对象,重新赋值Shader 代码: //修正s ...

  9. 【EF6学习笔记】(二)操练 CRUD 增删改查

    本篇原文链接: Implementing Basic CRUD Functionality 说明:学习笔记参考原文中的流程,为了增加实际操作性,并能够深入理解,部分地方根据实际情况做了一些调整:并且根 ...

  10. mysql 多表删除

    删除用户数据,我们就需要删除有关用户的所有数据. 主表是有数据的,其他关联表不一定有数据,我们可以用left join 来关联删除的表. eg:table1 是主表,t2,t3是关联表. SELECT ...