国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > ASP > 正文

asp正則html的圖片,對圖自動縮放大小

2020-07-27 13:01:24
字體:
供稿:網(wǎng)友
下面這個(gè)是比較不錯(cuò)的一個(gè)
復(fù)制代碼 代碼如下:

Function FormatImg2(content) 
           dim re
           Set re=new RegExp
           re.IgnoreCase =true
           re.Global=True
           re.Pattern="(script)"
           Content=re.Replace(Content,"script")
           re.Pattern="<img.[^>]*src(=| )(.[^>]*)>"
         Content=re.replace(Content,"<img src=$2  style=""cursor: pointer"" alt=""點(diǎn)此在新窗口瀏覽圖片"" onclick=""javascript:window.open(this.src);"" onload=""javascript:resizepic(this)"" border=""0""/>")
          set re = nothing
          FormatImg = content
        end function

上面有點(diǎn)不好的就是對于圖片中的寬度和高度都不存在了
復(fù)制代碼 代碼如下:

Function getphoto(strHTML) 
Dim objRegExp, Match, Matches 
Set objRegExp = New Regexp
objRegExp.IgnoreCase = True 
objRegExp.Global = True 
objRegExp.Pattern = "<img.+?>" 
tp=""
Set Matches = objRegExp.Execute(strHTML)
For Each Match in Matches 
tp=tp & Match.value 
exit for
Next 
getphoto=tp
Set objRegExp = Nothing 
End Function

下面的代碼時(shí)進(jìn)行圖片按比例縮放
復(fù)制代碼 代碼如下:

function ResizeImage(imageid,limitWidth,limitHeight) 
{     
    var image = new Image(); 
    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; 
        } 
    } 
    else if(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;
function InitImages() 

//圖片的約束寬度和高度
   var maxWidth = 100; 
    var maxHeight = 100; 
    var imgs = document.getElementsByTagName("img"); 
    for(var i=0; i < imgs.length; i++) 
    { 
        var img = imgs; 
        if(img.width>maxWidth||img.height>maxHeight) 
            ResizeImage(img, maxWidth, maxHeight); 
    } 
}
發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 集贤县| 商河县| 施秉县| 荆州市| 象山县| 松潘县| 阿拉善右旗| 额济纳旗| 河北省| 石台县| 大同县| 东乡族自治县| 赫章县| 长宁县| 六安市| 青州市| 罗定市| 长泰县| 叶城县| 法库县| 镇坪县| 永泰县| 韶关市| 乌鲁木齐市| 舟曲县| 全南县| 厦门市| 惠州市| 齐齐哈尔市| 连平县| 温州市| 东乌| 金华市| 革吉县| 宜君县| 福安市| 洛宁县| 浦东新区| 桂林市| 罗田县| 乌鲁木齐市|