file控件也能使用onchange。
<html>
<head>
<title>previewzdz</title>
<style>
html,body{font-size:12px;padding-top:3px;padding-left:3px;padding-right:0px;margin:0px}
p{margin:0;padding:0;}
</style>
</head>
<body>
<script>
functionpreview()
{
varfileext=document.form1.UpFile.value.substring(document.form1.UpFile.value.lastIndexOf("."),document.form1.UpFile.value.length)
fileext=fileext.toLowerCase()
if((fileext!='.jpg')&&(fileext!='.gif')&&(fileext!='.jpeg')&&(fileext!='.png')&&(fileext!='.bmp'))
{
alert("对不起,系统仅支持标准格式的照片,请您调整格式后重新上传,谢谢!");
document.form1.UpFile.focus();
}
else
{
//alert(''+document.form1.UpFile.value)//把这里改成预览图片的语句
document.getElementById("preview").innerHTML="<imgsrc='"+document.form1.UpFile.value+"'width=120style='border:6pxdouble#ccc'>"
}
}
</script>
<formname="form1"method="POST"enctype="multipart/form-data">
<inputtype="file"name="UpFile"size="46"onchange="preview()">
<divid="preview"></div>
</form>
</body>
</html>
http://www.corange.cn/archives/2008/08/1411.html
<html>
<head>
<title>previewzdz</title>
<style>
html,body{font-size:12px;padding-top:3px;padding-left:3px;padding-right:0px;margin:0px}
p{margin:0;padding:0;}
</style>
</head>
<body>
<script>
functionpreview()
{
varfileext=document.form1.UpFile.value.substring(document.form1.UpFile.value.lastIndexOf("."),document.form1.UpFile.value.length)
fileext=fileext.toLowerCase()
if((fileext!='.jpg')&&(fileext!='.gif')&&(fileext!='.jpeg')&&(fileext!='.png')&&(fileext!='.bmp'))
{
alert("对不起,系统仅支持标准格式的照片,请您调整格式后重新上传,谢谢!");
document.form1.UpFile.focus();
}
else
{
//alert(''+document.form1.UpFile.value)//把这里改成预览图片的语句
document.getElementById("preview").innerHTML="<imgsrc='"+document.form1.UpFile.value+"'width=120style='border:6pxdouble#ccc'>"
}
}
</script>
<formname="form1"method="POST"enctype="multipart/form-data">
<inputtype="file"name="UpFile"size="46"onchange="preview()">
<divid="preview"></div>
</form>
</body>
</html>
http://www.corange.cn/archives/2008/08/1411.html