高分求救img自动缩略的功能

655 2005-01-26 12:42:36
现在blog和bbs基本上都有这个功能了,大图自动缩略的功能,点开后可以看原始尺寸。
可基本都是针对UBB标签的,有没有方法可以直接从html中识别img标签进行操作呢?
请高手赐教,THX!!!
...全文
123 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
655 2005-01-28
  • 打赏
  • 举报
回复
求JSP的
655 2005-01-28
  • 打赏
  • 举报
回复
asp的方法:

<%
Dim re, strMatches, strMatch, tmpStr1, tmpStr2
Set re=new RegExp
re.IgnoreCase =True
re.Global=True

re.Pattern="\[img\](.*?)\[\/img\]"
Set strMatches=re.Execute(strContent)
For Each strMatch In strMatches
tmpStr1=CheckLinkStr(strMatch.SubMatches(0))
strContent=Replace(strContent,strMatch.Value,"<img src="""&tmpStr1&""" border=""0"" onload=""javascript:DrawImage(this);"" alt=""按此在新窗口打开图片"" onmouseover=""this.style.cursor='hand';"" onclick=""window.open(this.src);"" />")
Next
Set strMatches=Nothing

re.Pattern="\[img=(left|right|center|absmiddle)\](.*?)\[\/img\]"
Set strMatches=re.Execute(strContent)
For Each strMatch In strMatches
tmpStr1=strMatch.SubMatches(0)
tmpStr2=CheckLinkStr(strMatch.SubMatches(1))
strContent=Replace(strContent,strMatch.Value,"<img src="""&tmpStr2&""" align="""&tmpStr1&""" onload=""javascript:DrawImage(this);"" border=""0"" alt=""按此在新窗口打开图片"" onmouseover=""this.style.cursor='hand';"" onclick=""window.open(this.src);"" />")
Next
Set strMatches=Nothing
%>
655 2005-01-27
  • 打赏
  • 举报
回复
谢谢您的帮助

我现在的问题是需要进行处理的这部分代码是从数据库中提出来的,用一个变量表示,例如<%=content%>。
而页面中其它部分的图片不需要调用这个方法进行处理,所以我就需要动态的向content所代表代码中的<img>标签中写入方法调用。
我想问的是怎样能这样动态的写入
ttyp 2005-01-26
  • 打赏
  • 举报
回复
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>

<BODY>
<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==false){
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;
}
}
}

function ref(ImgD)
{
flag =!flag;
if(flag)
{
var image=new Image();
var iwidth = 80; //定义允许图片宽度
var iheight = 80; //定义允许图片高度
image.src=ImgD.src;
ImgD.width=image.width;
ImgD.height=image.height;
}
else
{
DrawImage(ImgD)
}


}
//-->
</script>

<img src="http://community.csdn.net/ADV/Images/csdn120x360.GIF" onload = "DrawImage(this)" onclick="ref(this)">
</BODY>
</HTML>

87,901

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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