直接上代码了

<!DOCTYPE html>
<html><head lang="en"><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,height=device-height,initial-scale=1.0,minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta name="apple-mobile-web-app-title" content="环球漫游">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="format-detection" content="telephone=no">
<meta name="keywords" content="环球漫游">
<meta name="description" content="环球漫游">
<title>个人资料</title>
<link rel="stylesheet" href="css/uroa-basic.css">
<link rel="stylesheet" href="css/user.css">
</head>
<body>
<div class="uroa-content">
<!--头部-->
<div class="uro-padeltwo">
<a href="index.html" class="urop-link urop-return"></a>
<h2 class="uro-title">个人资料</h2>
</div>
<p class="base-resourse">基本资料</p>
<div class="uroa-qhj">
<span class="yhwidth">头像</span>
<div class="user-photo">
<img src="./images/user-img.png" id="seeImg" />
<input id="file_head" class="file-3" type="file" size="30" onchange="javascript:setImagePreview(event);" accept="image/*" capture="camera">
</div>
</div> <div class="uroa-qhj">
<a href="http://www.baidu.com">
<span class="yhwidth">昵称</span>
<i class="des-yh">微信用户名</i>
</a>
</div> <div class="uroa-qhj">
<a href="http://www.baidu.com">
<span class="yhwidth">性别</span>
<i class="des-yh">男</i>
</a>
</div>
<div class="uroa-qhj bottom-none">
<span class="yhwidth">生日</span>
<input type="text" name="" class="des-brithday " value="2016-01-21" id="brithday" readonly="readonly" />
</div>
<p class="base-resourse">其他资料</p>
<div class="uroa-qhj">
<a href="http://www.baidu.com">
<span class="yhwidth">姓名</span>
<i class="des-yh">用户名</i>
</a>
</div>
<div class="uroa-qhj none-bg bottom-none">
<span class="yhwidth">手机号</span>
<i class="des-yh">181****4152</i>
</div> </div>
<script type="text/javascript" src="js/jquery-1.8.3.min.js"></script>
<script type="text/javascript">
function setImagePreview(event) {
var seeImg = document.getElementById('seeImg');
//seeImg.src=picture;
var files = event.target.files, file;
if (files && files.length > 0) {
// 获取目前上传的文件
file = files[0];
// 来在控制台看看到底这个对象是什么
console.log(file);
// 那么我们可以做一下诸如文件大小校验的动作
if(file.size > 1024 * 1024 * 2) {
alert('图片大小不能超过 2MB!');
return false;
}
// !!!!!!
// 下面是关键的关键,通过这个 file 对象生成一个可用的图像 URL
// 获取 window 的 URL 工具
var URL = window.URL || window.webkitURL;
// 通过 file 生成目标 url
var imgURL = URL.createObjectURL(file);
// 用这个 URL 产生一个 <img> 将其显示出来
// $('body').append($('<img/>').attr('src', imgURL));
seeImg.src=imgURL;
// 使用下面这句可以在内存中释放对此 url 的伺服,跑了之后那个 URL 就无效了
// URL.revokeObjectURL(imgURL);
}
}
</script>
</body>
</html>

css

/*#个人中心页面-头像修改*/
.userlogin-box{position: relative; top: 15px;width: 100%;height:60px;line-height: 60px;padding: 10px 15px;box-sizing: border-box;}
.img-left{width: 60px;height:60px;float: left;display: inline-block;}
.user-re{width: 123px; height: 44px; float: left;display: inline-block;margin-top: 3px; margin-left: 16px;}
.user-re p{width: 123px;height: 22px; display: inline-block;margin:; line-height: 22px;
float: left;font-size: 15px;color:#ffffff;}
.imgbod{width: 49px;height: 49px;display: inline-block;border-radius: 50%;}
.user-iphone-bg{background: url(../images/userindex_iphone.png) no-repeat left; background-size:8px 14px; padding-left:10px;}
/*个人中心跳转*/
.user-link{width: 75px;height: 50px;line-height: 50px;float: right;}
.urser-presonal{font-size: 15px;color: #ffffff;background: url(../images/user_right.png) no-repeat right;background-size:10px 15px;padding-right: 13px; }
.user-photo img{width: 100%;}
.user-photo{ position: relative;overflow: hidden;}
.file-3{position: absolute;
top:;
right:;
bottom:;
border:;
padding:;
margin:;
height: 32px;
width: 100%;
cursor: pointer;
opacity:; }

html 上传预览图片的更多相关文章

  1. 上传预览图片的插件jquery-fileupload

    上传预览图片的插件jquery-fileupload github地址:https://github.com/blueimp/jQuery-File-Upload 中文文档:http://www.jq ...

  2. 微信开发中使用微信JSSDK和使用URL.createObjectURL上传预览图片的不同处理对比

    在做微信公众号或者企业微信开发业务应用的时候,我们常常会涉及到图片预览.上传等的处理,往往业务需求不止一张图片,因此相对来说,需要考虑的全面一些,用户还需要对图片进行预览和相应的处理,在开始的时候我使 ...

  3. 异步上传&预览图片-不压缩图片

    本例使用ajaxFileUpload异步上传预览图片 <bean id="multipartResolver" class="org.springframework ...

  4. 上传预览图片自己做的.md

    1.无插件预览(window.URL.createObjectURL) ```javascript //demo 图片预览  单个 $(".demo input#demo_file" ...

  5. 异步上传&预览图片-压缩图片

    移动端普及的时代,流量是用户最关心的,手机拍出来的照片基本上都在1~2M以上,这样上传会非常耗流量,影响用户体验,此例能在保证清晰度的情况下,将4.5M的图片压缩为30K <!DOCTYPE h ...

  6. javascript 上传 预览图片 兼容 谷歌 ie

    最近的项目要用到这块,但是在网上找了很多资料,很多都是假的,都不行,最后终于找到一个,还是可以兼容主流的,特分享给大家,可以用 <!DOCTYPE html PUBLIC "-//W3 ...

  7. Vue 中使用 viewerjs进行本地上传预览图片

    https://www.cnblogs.com/shenjp/p/9754171.html 如果图片路径是 接口的返回信息的话,将路径存储在数组中,在this.$nextTick中实例化Viewer: ...

  8. 兼容好的JS图片上传预览代码

    转 : http://www.codefans.net/articles/1395.shtml 兼容好的JS图片上传预览代码 (谷歌,IE11) <html xmlns="http:/ ...

  9. Jquery图片上传预览效果

    uploadPreview.js jQuery.fn.extend({ uploadPreview: function (opts) { var _self = this, _this = $(thi ...

随机推荐

  1. js 实现类似php函数number_format的功能

    今天同事在做一个功能的时候需要使用js来实现类似php函数number_format的功能,最后就有了下面的方法,可以实现了: /** * number_format * @param number ...

  2. ARP协议学习

    1.地址解析协议,即ARP(Address Resolution Protocol),是根据IP地址获取物理地址的一个TCP/IP协议.所以,ARP就是把IP地址解析为MAC地址. 2.如何查看和清除 ...

  3. noi 1.5 43:质因数分解

    描述 已知正整数 n 是两个不同的质数的乘积,试求出较大的那个质数. 输入 输入只有一行,包含一个正整数 n.对于60%的数据,6 ≤ n ≤ 1000.对于100%的数据,6 ≤ n ≤ 2*10^ ...

  4. Url通配符映射

    原文:http://www.cnblogs.com/liukemng/p/3726897.ht 1.URL路径映射 1.1.对一个action配置多个URL映射: 我们把上一篇中的HelloWorld ...

  5. C++中的"未定义的行为"

    2.1 位运算 位运算的运算对象是整数类型的,并且把运算对象看成是一个二进制位的集合.运算对象可以是带符号也可以是无符号.如果是带符号且值为负,那么位运算如何处理运算对象的符号位依赖于机器.而且此时的 ...

  6. Linux opencv安装与编译

    参考http://blog.csdn.net/solomon1558/article/details/51967280 1安装cmake以及依赖库 $ sudo apt-get install cma ...

  7. Scala学习笔记之二--基本数据类型

    前言 本篇主要讲Scala的基本数据类型,更多教程请参考:Scala教程 基本数据类型 Scala一共提供了9中数据类型,Scala的基本数据类型与java中的基本数据类型是一一对应的,这是Scala ...

  8. apiCloud图片选择、处理、上传模块

    将 apiCloud 开发app的图片上传流程,完整封装成了一个页面,页面处理一些必备的处理库外和css外 ,还需要依赖jquery 库,不过可以不管,页面默认使用cnd引用. 页面使用接口如下:pa ...

  9. js 控制Div循环显示 非插件版

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  10. Core Data 使用映射模型

    Core Data 使用映射模型 如果新版本的模型存在较复杂的更改,可以创建一个映射模型,通过该模型指定源模型如何映射到目标模型. 创建映射模型,新建File,  Core Data 选择Mappin ...