input file图片上传
<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图片上传的更多相关文章
- input file 图片上传
使用第三方:jquery.ajaxfileupload.jsinput中的name根据后端来定 <form method="post" enctype="multi ...
- form input file 图片上传360IE兼容问题
<form action="" class="form-box" class="form_box" enctype="mul ...
- input file图片上传预览
两种方法,方法一: js代码: //头像上传预览 $("#up").change(function() { var $file = $(this); var fileObj = $ ...
- input file图片上传预览效果
两种方法,方法一: js代码: //头像上传预览 $("#up").change(function() { var $file = $(this); var fileObj = $ ...
- input file 图片上传展示重新上传
html <div> <label class="imgMark">说明:</label> <div class="erWeiM ...
- js 实现 input file 文件上传
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat=&qu ...
- input file 文件上传标签的样式美化
input file 文件上传标签的样式美化 将<input type="file">的透明度设置为0: <input type="file" ...
- PHP 多input file文件上传
前台html jquery代码 后台PHP处理 前台html <form id="form" method="post" enctype="mu ...
- file图片上传之前先预览
链接:https://www.cnblogs.com/tandaxia/p/5125275.html 记得以前做网站时,曾经需要实现一个图片上传到服务器前,先预览的功能.当时用html的<inp ...
随机推荐
- 把ajax包装成promise的形式(3)
概述 为了体验promise的原理,我打算自己把ajax包装成promise的形式.主要希望实现下列功能: // 1.使用success和error进行链式调用,并且可以在后面加上无限个 promis ...
- Kali学习笔记10:端口扫描详解(下)
上一篇先是介绍了UDP的端口扫描,又谈了TCP的不完全连接端口扫描 https://www.cnblogs.com/xuyiqing/p/9389276.html 接下来我们看看TCP的全连接端口扫描 ...
- Kali学习笔记7:三层发现
三层发现:发送ICMP/IP数据包探测 第一种方式: 就是很简单的Ping命令: 不过linux的ping命令和windows的ping命令不一样,它会默认不停止地发数据包 我们可以通过-c参数来设置 ...
- Python - 浅谈Python的编译与反编译
1 - Python编译过程涉及的文件 py 源代码文件,由python.exe解释,可在控制台下运行,可用文本编辑器进行编辑: pyc 源代码文件经过编译后生成的二进制文件,无法用文本编辑器进行编辑 ...
- Source Qualifter组件中sqlquery过长导致截取
问题:Source Qualifter组件中sqlquery过长导致截取原因:Source Qualifter组件中sqlquery可以接受的最长字符数是32767个字符,超过这个数字会导致截取解决方 ...
- Effective Java 第三版——60. 需要精确的结果时避免使用float和double类型
Tips 书中的源代码地址:https://github.com/jbloch/effective-java-3e-source-code 注意,书中的有些代码里方法是基于Java 9 API中的,所 ...
- 使用Redis中间件解决商品秒杀活动中出现的超卖问题(使用Java多线程模拟高并发环境)
一.引入Jedis依赖 可以新建Spring或Maven工程,在pom文件中引入Jedis依赖: <dependency> <groupId>redis.clients< ...
- freemarker常见语法大全,灰常有用!
由于公司前端使用的技术是freemarker,于是没事就在网上看看别人写的关于freemarker的文章,感觉freemarker灰常简单,比jsp好用,jsp太乱太臃肿了,另外推荐大家看看freem ...
- ML - 特征选择
1. 决策树中的特征选择 分类决策树是一种描述对实例进行分类的树型结构,决策树学习本质上就是从训练数据集中归纳出一组分类规则,而二叉决策树类似于if-else规则.决策树的构建也是非常的简单,首先依据 ...
- vue 解决无法设置滚动位置的问题
问题描述 在实现锚点定位的时候发现无法设置滚动条的位置. 在Vue中,使用 document.body.scrollTop=952 无法设置滚动条的高度. document.body.scrollTo ...