有图片预览功能的上传表单HTML代码

2017-01-04 11:42:34 有图片预览功能的上传表单HTML代码

代码如下:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>图片上传</title>
<script>
function viewmypic(mypic,imgfiles) {
if (imgfiles.value){
mypic.src=imgfiles.value;
mypic.style.display="";
mypic.border=1;
}
}
</script>
</head>
<body>
<center>
<form >
<input name="imgfiles" type="file" id="imgfiles" size="40" onchange="viewmypic(showimg,this.form.imgfiles);" />
<br />
</form>
<img name="showimg" id="showimg" src="" style="display:none;" alt="预览图片" />
<br />
</div>
<div style="display:none">
</div>
</center>
</body>
</html>
更新