js本地预览图片
废话不说 直接上代码
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<body>
<img id="image" src=""/>
<br/>
<input type="file" id="file" onchange="selectImage(this);"/> <br>
<br/>
<script>
function selectImage(file) {
alert(file.value.substring(file.value.lastIndexOf('.')));
if (!file.files || !file.files[0]) {
return;
}
var reader = new FileReader();
reader.onload = function (evt) {
var data = evt.target.result;
//加载图片获取图片真实宽度和高度
var image = new Image();
image.onload=function(){
var width = image.width;
var height = image.height;
alert(width+'======'+height+"====="+file.files[0].size+'1');
};
image.src= data;
document.getElementById('image').src = evt.target.result;
}
reader.readAsDataURL(file.files[0]);
$("#image").attr({'width':'100px','height':'100px'});
}
</script>
</body>
</html>
最新文章
- ES6(二)解构赋值详解
- iOS学习36数据处理之SQLite数据库
- access里like的通配符不能用%,要用*
- Net Core- 配置组件
- linux grep命令详解(转)
- [leetcode-357-Count Numbers with Unique Digits]
- 最简单获取appPackage和appActivity 的方法
- js滚动到指定位置
- [luogu P2054] [AHOI2005]洗牌
- Android分组子级的不同视图布局之BUG奇遇记
- 09 Go 1.9 Release Notes
- JSP字符集编码集合
- Java中-classpath和路径的使用
- java中如何打war包
- BZOJ4145_The Prices_KEY
- PSP Daily软件beta版本——基于spec评论
- 【BZOJ】3991: [SDOI2015]寻宝游戏 虚树+DFS序+set
- 3D Math Keynote
- hadoop3.1 hdfs的api使用
- delphi xe5 安卓 配置sqlite