javascript预览图片,按比例控制图片大小
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>图片预览</title>
<script>
function PreviewPhotoatwidth(photo_file,img_object,imgwidth)
{
var fileext=photo_file.value.substring(photo_file.value.lastIndexOf("."),photo_file.value.length);
fileext=fileext.toLowerCase();
if ((fileext!='.jpg')&&(fileext!='.gif')&&(fileext!='.jpeg')&&(fileext!='.png')&&(fileext!='.bmp'))
{alert("对不起,系统仅支持标准格式的照片,请您调整格式后重新上传,谢谢 !");
photo_file.focus();
}
else
{
img_object.src=photo_file.value;
if (img_object.width>imgwidth)
{
img_object.width=imgwidth;
}
}
}
</script>
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center"><img id="picpreview" alt='预览' /></td>
</tr>
<tr>
<td align="center"><form id="form1" name="form1" enctype="multipart/form-data" method="post" action="">
<label>update
<input type="file" id="uppic" name="uppic" onchange="javascript:PreviewPhotoatwidth(this,picpreview,260)" />
</label>
</form>
</td>
</tr>
<tr>
<td> </td>
</tr>
</table>
</body>
</html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>图片预览</title>
<script>
function PreviewPhotoatwidth(photo_file,img_object,imgwidth)
{
var fileext=photo_file.value.substring(photo_file.value.lastIndexOf("."),photo_file.value.length);
fileext=fileext.toLowerCase();
if ((fileext!='.jpg')&&(fileext!='.gif')&&(fileext!='.jpeg')&&(fileext!='.png')&&(fileext!='.bmp'))
{alert("对不起,系统仅支持标准格式的照片,请您调整格式后重新上传,谢谢 !");
photo_file.focus();
}
else
{
img_object.src=photo_file.value;
if (img_object.width>imgwidth)
{
img_object.width=imgwidth;
}
}
}
</script>
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center"><img id="picpreview" alt='预览' /></td>
</tr>
<tr>
<td align="center"><form id="form1" name="form1" enctype="multipart/form-data" method="post" action="">
<label>update
<input type="file" id="uppic" name="uppic" onchange="javascript:PreviewPhotoatwidth(this,picpreview,260)" />
</label>
</form>
</td>
</tr>
<tr>
<td> </td>
</tr>
</table>
</body>
</html>
从一个CNBLOGS朋友那里找到 记下 分享
http://www.cnblogs.com/cowboy/archive/2006/10/14/390808.html