<script>
function checkData()
{
var fileName=document.getElementById("myFile").value;
if(fileName=="")
return;
var exName=fileName.substr(fileName.lastIndexOf(".")+1).toUpperCase()
//alert(exName)
if(exName=="JPG"||exName=="BMP"||exName=="GIF")
{
document.getElementById("myimg").src=fileName
}
else
{
alert("请选择正确的图片文件")
document.getElementById("myFile").value=""
}
}
</script>
选择照片控件:
<INPUT id="myFile" type="file" onchange="checkData()" size="34" name="myFile" runat="server">
显示图片(不选择显示默认图片):
<IMG id="myimg" height="160" alt="" src="../images/nopicnews.gif" width="140">
function checkData()
{
var fileName=document.getElementById("myFile").value;
if(fileName=="")
return;
var exName=fileName.substr(fileName.lastIndexOf(".")+1).toUpperCase()
//alert(exName)
if(exName=="JPG"||exName=="BMP"||exName=="GIF")
{
document.getElementById("myimg").src=fileName
}
else
{
alert("请选择正确的图片文件")
document.getElementById("myFile").value=""
}
}
</script>
选择照片控件:
<INPUT id="myFile" type="file" onchange="checkData()" size="34" name="myFile" runat="server">
显示图片(不选择显示默认图片):
<IMG id="myimg" height="160" alt="" src="../images/nopicnews.gif" width="140">