代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<style type="text/css">
#preview{width:260px;height:190px;border:1px solid #000;overflow:hidden;}
#imghead {filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=image);}
</style>
<body>
<div id="preview">
<img id="imghead" width=100 height=100 border=0 src='images/defaul.jpg'>
</div>
<input type="file" onchange="previewImage(this)" />
</body>
<script>
//预览图片
function previewImage(file) {
var fileReader = new FileReader();
var img = document.getElementById('imghead');
fileReader.onload = function(evt)
{
if(FileReader.DONE==fileReader.readyState)
{
img.src = evt.target.result;
}
};
fileReader.readAsDataURL(file.files[0]);
}
</script>
</html>