您正在使用 IPV6 [2600:1f28:365:80b0:b995:4506:c783:413] 访问本站,您本次已经查看了 1 页
用户名: 密 码: 验证码:     用QQ登录本站
首页 软件 编程 笑话 知识 公告 台风 日历 计算器
[公益]保护绿色环境,构建和谐社会      

【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中      
广州婚姻调查公司       [公益] 地球是我家,绿化靠大家       【腾讯云】618年中盛惠,2核2G5M云服务器低至 68元/年      
2025年 七夕节 069
2025年 教师节 081
2026年 元 旦 194
2026年 春 节 241
综合数码金融娱乐服务报刊政府机构 推荐 排名 今日 申请 友情  
您现在的位置:首页 >> ASP/ASP.net >> 内容
本类新增
本类热门
asp正则html的图片,对图自动缩放大小
内容摘要: FunctionFormatImg2(content)dimreSetre=newRegExpre.IgnoreCase=truere.Global=Truere.Pattern='(script)'Content=re.Replace(Content,'script')re.Pattern='img.[^]*src(=|)(.[^]*)'Content=r......
FunctionFormatImg2(content)

dimre

Setre=newRegExp

re.IgnoreCase=true

re.Global=True

re.Pattern="(script)"

Content=re.Replace(Content,"script")

re.Pattern="<img.[^>]*src(=|)(.[^>]*)>"

Content=re.replace(Content,"<imgsrc=$2style=""cursor:pointer""alt=""点此在新窗口浏览图片""onclick=""javascript:window.open(this.src);""onload=""javascript:resizepic(this)""border=""0""/>")

setre=nothing

FormatImg=content

endfunction

上面有点不好的就是对于图片中的宽度和高度都不存在了

代码如下:

Functiongetphoto(strHTML)

DimobjRegExp,Match,Matches

SetobjRegExp=NewRegexp

objRegExp.IgnoreCase=True

objRegExp.Global=True

objRegExp.Pattern="<img.+?>"

tp=""

SetMatches=objRegExp.Execute(strHTML)

ForEachMatchinMatches

tp=tp&Match.value

exitfor

Next

getphoto=tp

SetobjRegExp=Nothing

EndFunction

下面的代码时进行图片按比例缩放

代码如下:

functionResizeImage(imageid,limitWidth,limitHeight)

{

varimage=newImage();

image.src=imageid.src;

if(image.width<=0&&image.height<=0)return;

if(image.width/image.height>=limitWidth/limitHeight)

{

if(image.width>limitWidth)

{

imageid.width=limitWidth;

imageid.height=(image.height*limitWidth)/image.width;

}

}

elseif(image.height>limitHeight)

{

imageid.height=limitHeight;

imageid.width=(image.width*limitHeight)/image.height;

}

if(imageid.parentElement.tagName!="A")

{

imageid.onclick=function(){window.open(this.src);}

imageid.style.cursor="hand";

}

}

window.onload=InitImages;

functionInitImages()

{

//图片的约束宽度和高度

varmaxWidth=100;

varmaxHeight=100;

varimgs=document.getElementsByTagName("img");

for(vari=0;i<imgs.length;i++)

{

varimg=imgs;

if(img.width>maxWidth||img.height>maxHeight)

ResizeImage(img,maxWidth,maxHeight);

}

}

版权声明:本内容来源于网络,如有侵犯您的版权,请联系站长,本站收到您的信息后将及时处理。
上一篇:asp在服务器把 XML 转换为 XHTML的实现代码

 

下一篇:Asp 操作Cookies(包括设置[赋值]、读取、删除[设

发布日期:2025/3/1
手机扫二维码直达本页
发布时间:20:58:24
点  击:24
录  入:壹家怡园
相关文章
Baidu
YiJiaCMS 7.5.8 build250610(MSSQL) 闽ICP备05000814号-1
本空间由腾讯云(轻量应用服务器)提供,创宇云安全提供加速防护
运行时间载入中.....
知道创宇云安全