前台代码:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body>
<input type="file" id="ProductImage" οnchange="upload()"/>
<img src="" id="image" />
</body>
</html>
js代码:
<script>
function upload() {
var fileReader = new FileReader();
//取到文件的对象
file = document.getElementById('ProductImage').files[0];
fileReader.readAsDataURL(file);
fileReader.onload = function (e) {
document.getElementById('image').src = this.result;
}
}
</script>