JS实现图片上传预览效果

<form>

<img ID="UserImg" /><br/>

<input type="file" name="fileimage" id="fileimage" style="display: none;"  />

<br />

<input id="Btn_UserImg" 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实现图片上传预览效果

上一篇:yolov5 初体验怎么用及训练数据集


下一篇:淘宝破裤子奇遇记--记酷锐哲型旗舰店