怎么把.图片等比缩放啊 <td width=200 ><img src='' id='pic'></td> 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <script language="JavaScript"> <!-- //图片按比例缩放 var flag=false; function DrawImage(ImgD){ var image=new Image(); var iwidth = 80; //定义允许图片宽度 var iheight = 80; //定义允许图片高度 image.src=ImgD.src; if(image.width>0 && image.height>0){ flag=true; if(image.width/image.height>= iwidth/iheight){ if(image.width>iwidth){ ImgD.width=iwidth; ImgD.height=(image.height*iwidth)/image.width; }else{ ImgD.width=image.width; ImgD.height=image.height; } ImgD.alt=image.width+"×"+image.height; } else{ if(image.height>iheight){ ImgD.height=iheight; ImgD.width=(image.width*iheight)/image.height; }else{ ImgD.width=image.width; ImgD.height=image.height; } ImgD.alt=image.width+"×"+image.height; } } } //--> </script> <img src=".." onload = "DrawImage(this)"> 我有好多z张要在 pic这个id里显示,每张大小都不一样 function img(src){ var image=new Image(); image.src = src; var w0 = image.width; var h0 = image.height; var w1 = 200; var h1 = 300; var r0 = w1/w0; var r1 = h1/h0; if(r0>r1) r0 = r1; w0 = w0*r0; h0 = h0*r0; pic.style.width = w0; pic.style.height = h0; pic.src = src;} 大家帮忙看看我这段js哪里错了 求高手看看这段代码!为什么在不同浏览器运行出错 求正则表达式 不包含<>/三个字符 EXT问题 得到record后怎么插入到store內? W3C DOM的标准属性和方法都有哪些啊? 还是一个关于event.srcElement在ff兼容的问题 关于批量删除文件的问题。大家帮我看看 JS任务栏滚动效果问题 onchange和onfocus onchange为什么没有效果 为什么显示不出来??急。。。。 关于showModalDialog的两个问题。 一个奇怪的问题(关于js的按钮事件)
<!--
//图片按比例缩放
var flag=false;
function DrawImage(ImgD){
var image=new Image();
var iwidth = 80; //定义允许图片宽度
var iheight = 80; //定义允许图片高度
image.src=ImgD.src;
if(image.width>0 && image.height>0){
flag=true;
if(image.width/image.height>= iwidth/iheight){
if(image.width>iwidth){
ImgD.width=iwidth;
ImgD.height=(image.height*iwidth)/image.width;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"×"+image.height;
}
else{
if(image.height>iheight){
ImgD.height=iheight;
ImgD.width=(image.width*iheight)/image.height;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"×"+image.height;
}
}
}
//-->
</script>
<img src=".." onload = "DrawImage(this)">
{
var image=new Image();
image.src = src;
var w0 = image.width;
var h0 = image.height;
var w1 = 200;
var h1 = 300;
var r0 = w1/w0;
var r1 = h1/h0; if(r0>r1) r0 = r1;
w0 = w0*r0;
h0 = h0*r0; pic.style.width = w0;
pic.style.height = h0;
pic.src = src;
}