会员
周边
众包
新闻
博问
闪存
赞助商
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
桂圆的编程世界
桂圆烟雨任平生
博客园
园子
首页
新随笔
联系
管理
订阅
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
>
从一个CNBLOGS朋友那里找到 记下 分享
http://www.cnblogs.com/cowboy/archive/2006/10/14/390808.html
posted @
2007-04-03 00:17
桂圆
阅读(
1299
) 评论(
2
)
编辑
收藏
举报
刷新页面
返回顶部
公告