js图片上传直接浏览的代码?
- 提问者网友:夢醒日落
- 2021-04-28 23:43
- 五星知识达人网友:神也偏爱
- 2021-04-29 01:21
<html >
<head>
<title>无标题页</title>
<style type="text/css">#newPreview {FILTER: progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale)}</style>
<script language="javascript" type="text/javascript">
function CheckImg(fileUpload)
{
var mime=fileUpload.value;
mime=mime.toLowerCase().substr(mime.lastIndexOf("."));
if(mime!=".jpg")
{
fileUpload.value="";
alert("仅支持JPG格式!");
}
else
{
var imags=document.getElementsByTagName("img");
for(i=0;i<imags.length;i++)
{
if(imags[i].name=='imagePhoto')
{
imags[i].src=fileUpload.value;
}
}
}
}
</script>
</head>
<body>
<form id="form1">
<table>
<tr>
<td>
<input id="ImagePath" type="file" onchange="CheckImg(this)"/>
</td>
</tr>
<tr>
<td>
<Image ID="imagePhoto" name="imagePhoto" runat="server" Height="180px" Width="230px" /></td>
</tr>
</table>
</form>
</body>
</html>
我写的上传直接浏览图片!