<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>上传预览</title>
<script>
function preview(){
var fileEle=document.getElementById("file");
var file=fileEle.files[0];
var reader = new FileReader();
reader.onload = function(e) {
var img=document.getElementById("img");
img.src=e.target.result
};
reader.readAsDataURL(file)
}
</script>
</head>
<body>
<div>
<input id="file" type="file"/>
<input type="button" value="预览" οnclick="preview()"/>
</div>
<div>
<img id="img" style="width:300px;height:200px;"/>
</div>
</body>
</html>
htm5文件上传预览
最新推荐文章于 2024-02-29 22:07:03 发布