应该挺简单

cp713 2008-12-04 10:56:33
<IMG src="../youxi/up-moni/<%Response.Write(rs("图2"))%>" alt="<%Response.Write(rs("名称"))%>2" border=0 onload='javascript:if(this.width>240)this.width=240;if(this.height>180)this.height=180'>


如何把上面的代码 写在<script language="javascript">
因为写在 body中onload有时后加载失败
如何在 img 中加个 id= 写在<script language="javascript">中
...全文
63 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
lobster_lshj 2008-12-05
  • 打赏
  • 举报
回复
<script language="JavaScript">
<!--
//图片按比例缩放
var flag=false;
function DrawImage(ImgD,iwidth,iheight){
//参数(图片,允许的宽度,允许的高度)
var image=new Image();
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>




<a href="http://luoxiaoyin.damingxing.cn/Photo_view_2931.html" target="_blank"><img onerror="this.src='/images/main/nopic.gif';" src="http://Media4qdfg.damingxing.cn/file10//200812/04/15/image/s_200812415364147115.jpg" width=120 border="0" align="absmiddle" onload="javascript:DrawImage(this,90,90)"></a>


用这个写法试试吧
lobster_lshj 2008-12-05
  • 打赏
  • 举报
回复
<script language="JavaScript">
<!--
//图片按比例缩放
var flag=false;
function DrawImage(ImgD,iwidth,iheight){
//参数(图片,允许的宽度,允许的高度)
var image=new Image();
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>




<a href="http://luoxiaoyin.damingxing.cn/Photo_view_2931.html" target="_blank"><img onerror="this.src='/images/main/nopic.gif';" src="http://Media4qdfg.damingxing.cn/file10//200812/04/15/image/s_200812415364147115.jpg" width=120 border="0" align="absmiddle" onload="javascript:DrawImage(this,90,90)"></a>


用这个写法试试吧
行间 2008-12-04
  • 打赏
  • 举报
回复
需要 new Image()

然后判断加载是否完成,写入宽度
nanchangfantasy 2008-12-04
  • 打赏
  • 举报
回复
没见过这种写法

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧