<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>test</title>
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
</head>
<style>
.btn{
	display: block;
	background:green;
	color:#fff;
	text-decoration:none;
	padding:5px;
	float: left;
	margin:0 5px;
}
</style>
<body>
	
	<label for="up">
		<input type="file" id="up" style="display:none;">
		<span class="btn">选择图片</span>
	</label>
	<a href="javascript:;" class="btn">上传</a>
	<img src="" id="pic">
</body>
</html>
<script>
	function $( id ){
		return document.getElementById(id);
	}
	//改变的时候才获取内容
	$(‘up‘).onchange = function(){
		if ( this.files != undefined ) {
			var url = window.webkitURL.createObjectURL( this.files[0] );
			$(‘pic‘).src = url;
		}
	}
</script>
原文:http://www.cnblogs.com/zion0707/p/4475403.html