格式,只保留SRC属性,去掉IMG标签的其他属性。

FunctionFixImg(sString)
  
    DimsReallyDo,regEx,iReallyDo
    DimoMatches,cMatch
    DimtStartTime,tEndTime
    IfIsNull(sString)Then
        FixImg=""
        ExitFunction
    EndIf
    sReallyDo=sString
    OnErrorResumeNext
    sReallyDo=Replace(sReallyDo,vbCr,"")
    sReallyDo=Replace(sReallyDo,vbLf,"")
    sReallyDo=Replace(sReallyDo,vbTab,"")
    sReallyDo=Replace(sReallyDo,"","/>",1,-1,1)
    sReallyDo=ReplaceAll(sReallyDo,"=","=",True)
    sReallyDo=ReplaceAll(sReallyDo,">",">",True)
    sReallyDo=Replace(sReallyDo,"><",">"&vbCrLf&"<")
    sReallyDo=Trim(sReallyDo)
    OnErrorGoTo0
    SetregEx=NewRegExp
    regEx.IgnoreCase=True
    regEx.Global=True
    '//去除onclick,onload等脚本
    regEx.Pattern="\s[on].+?=([\""|\'])(.*?)\1"
    sReallyDo=regEx.Replace(sReallyDo,"")
    '//将SRC不带引号的图片地址加上引号
    regEx.Pattern="]*).*?>"
    sReallyDo=regEx.Replace(sReallyDo,"")
    '//正则匹配图片SRC地址
    regEx.Pattern=""
    sReallyDo=regEx.Replace(sReallyDo,"")
    FixImg=sReallyDo
EndFunction

上面的代码确实写得不错,原理也可以参考下面的代码

js过滤img里style属性

varstr=""
str=str.replace(/]*>/gi,function(match,capture){
returnmatch.replace(/style\s*?=\s*?([‘"])[\s\S]*?\1/ig,'')
}))
console.log(str)

不是替换直接通过js设置

varis=document.images;
for(vari=0,len=is.length;i

到此这篇关于ASP删除img标签的style属性只保留src的正则函数的文章就介绍到这了,更多相关ASP去除img的style属性内容请搜索毛票票以前的文章或继续浏览下面的相关文章希望大家以后多多支持毛票票!

热门推荐

免责声明:网站资源来源于网络,如有侵权,请及时联系删除。

Copyright © 2025 好资源导航网. All Rights Reserved.

蜀ICP备2021004611号-4 网站地图