JS实现图片上传预览效果
<form>
<img /><br/>
<input type="file" name="fileimage" />
<br />
<input type="button" value="选择图片" />
<script>
function Urlimg(e) {
var url = null;
if (window.URL != null) {
url = window.URL.createObjectURL(e);
} else if (window.createObjectURL != null) {
url = window.createObjectURL(e);
} else if (window.webkitURL != null) {
url = window.webkitURL.createObjectURL(e);
}
return url;
};
document.getElementById("Btn_UserImg").onclick = function() {
document.getElementById("fileimage").click();
document.getElementById("fileimage").onchange = function() {
var img = Urlimg(document.getElementById("fileimage").files[0]);
document.getElementById("UserImg").setAttribute("src", img);
};
};
</script>
</form>
JS实现图片上传预览效果
原文:https://www.cnblogs.com/LanHai12/p/15258188.html