H5 实现图片上传预览
<!DOCTYPE html>
<html> <head>
<meta charset="utf-8" />
<title>图片上传预览</title>
<style>
.check_box{
position: relative;
width: 100px;
height: 100px;
margin: 20px;
display: flex;
flex-direction: row;
align-items: center;
}
#img_preview1{
display: block;
width: 100px;
height: auto;
}
input#zx_img1 {
position: absolute;
top: 0;
left: 0;
width: 100px;
height: 100px;
opacity: 0;
z-index: 9;
} </style>
</head> <body> <div class="check_box">
<img id="img_preview1" src="./images/add.png" alt="上传图片">
<input type="file" name="file" id="zx_img1" style="padding: 0px;" accept="image/jpeg, image/jpg, image/png, image/gif "
placeholder=" 上传文件">
</div>
<p>
图片大小支持50kb以内,支持拓展名:jpg,png,gif
</p> <!--引入jQuery插件 -->
<script src="https://cdn.bootcss.com/jquery/3.3.0/jquery.min.js"></script>
<script>
$("#zx_img1").change(function (e) {
var file = e.target.files || e.dataTransfer.files;
if (file) { if (file[0] && (file[0].size / 1024).toFixed(0) > 50) {
console.log('你选择的文件太大,文件大小为:' + (file[0].size / 1024).toFixed(0) + "kb");
// return false
}
var reader = new FileReader();
reader.onload = function () {
console.log(this.result);
$("#img_preview1").attr("src", this.result);
}
reader.readAsDataURL(file[0]);
}
});
</script>
</body> </html>
H5 实现图片上传预览的更多相关文章
- 图片上传预览,兼容IE
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 用html5文件api实现移动端图片上传&预览效果
想要用h5在移动端实现图片上传&预览效果,首先要了解html5的文件api相关知识(所有api只列举本功能所需): 1.Blob对象 Blob表示原始二进制数据,Html5的file对象就继 ...
- 兼容好的JS图片上传预览代码
转 : http://www.codefans.net/articles/1395.shtml 兼容好的JS图片上传预览代码 (谷歌,IE11) <html xmlns="http:/ ...
- Jquery图片上传预览效果
uploadPreview.js jQuery.fn.extend({ uploadPreview: function (opts) { var _self = this, _this = $(thi ...
- [前端 4] 使用Js实现图片上传预览
导读:今天做图片上传预览,刚开始的做法是,先将图片上传到Nginx,然后重新加载页面才能看到这个图片.在这个过程中,用户一直都看不到自己上传的文件是什么样子.Ps:我发现我真的有强迫症了,都告诉我说不 ...
- Javascript之图片上传预览
使用Javascript之图片上传预览,我们无需上传到服务器中,兼容所有浏览器. 关键方法是使用微软库filter:progid:DXImageTransform.Microsoft.AlphaIma ...
- HTML5 图片上传预览
<!DOCTYPE html> <html lang="zh-cn"> <head> <meta charset="utf-8& ...
- ASP.NET工作笔记之一:图片上传预览及无刷新上传
转自:http://www.cnblogs.com/sibiyellow/archive/2012/04/27/jqueryformjs.html 最近项目里面涉及到无刷新上传图片的功能,其实也就是上 ...
- php 图片上传预览(转)
网上找的图片上传预览: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:/ ...
随机推荐
- 多线程之 Runnable接口
一.多线程实现的第二种方式 1.定义类,实现Runnable接口 2.重写接口中的run方法,要在run方法中定义线程要执行的任务 public class MyRunnableImpl implem ...
- elasticsearch5.0以上版本及head插件的安装
本文转载至:https://www.cnblogs.com/hts-technology/p/8477258.html(针对5.0以上版本) 对于es5.0以下的版本可以参考:https://www. ...
- Hibernate原理及应用
Hibernate工作原理及为什么要用? 原理:1.通过Configuration().configure();读取并解析hibernate.cfg.xml配置文件2.由hibernate.cfg.x ...
- SharePoint Framework 向web部件中添加外部库
博客地址:http://blog.csdn.net/FoxDave 在进行开发的时候,你很可能会想要引用一些公开的JavaScript库到你的项目中,本文将会介绍如何打包和共享这些库. 打包脚本 默认 ...
- Unable to correct problems, you have held broken packages
Use aptitude instead of apt-get. It is more intelligent. It not only will handle downgrading conflic ...
- PTA-栈
1-1 若一个栈的输入序列为1,2,3,…,N,输出序列的第一个元素是i,则第j个输出元素是j−i−1. (2分) T F 作者: DS课程组 单位: 浙江大学 1-2 若一个栈的 ...
- day13 内置函数一
见如下网址 https://www.processon.com/mindmap/5bdc3f49e4b0844e0bc6b5d3
- openstack之neutron配额调整
1. 前言 neutron在安装配置完成之后,openstack为了实现对所有tenant对网络资源的使用,针对neutron设置有专门的配额,以防止租户使用过多的资源,而对其他的tena ...
- Python 常见字符串常量和表达式
常见字符串常量和表达式 操作 解释 s = '' 空字符串 s = "spam's" 双引号和单引号相同 S = 's\np\ta\x00m' 转义序列 s = "&qu ...
- Some notes in Stanford CS106A(2)
1.Local variable(local) ex. int i = 0; factorial(i); the "i" outside the method factorial( ...