<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>