file 控件也能使用 onchange。
<html>
<head>
<title>preview zdz</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>
function preview()
{
var fileext=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="<img src='"+document.form1.UpFile.value+"' width=120 style='border:6px double #ccc'>"
}
}
</script>
<form name="form1" method="POST" enctype="multipart/form-data">
<input type="file" name="UpFile" size="46" onchange="preview()">
<div id="preview"></div>
</form>
</body>
</html>
http://www.corange.cn/archives/2008/08/1411.html
<html>
<head>
<title>preview zdz</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>
function preview()
{
var fileext=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="<img src='"+document.form1.UpFile.value+"' width=120 style='border:6px double #ccc'>"
}
}
</script>
<form name="form1" method="POST" enctype="multipart/form-data">
<input type="file" name="UpFile" size="46" onchange="preview()">
<div id="preview"></div>
</form>
</body>
</html>
http://www.corange.cn/archives/2008/08/1411.html
本文介绍了一个使用HTML和JavaScript实现的文件上传功能,并在用户选择文件后立即进行预览的方法。该方法支持常见的图片格式,如jpg、gif、jpeg、png和bmp。此外,还包含了对非标准格式文件的提示及限制。
772

被折叠的 条评论
为什么被折叠?



