相思资源网 Design By www.200059.com
ASP去除img标签style属性只保留src
'功能:将IMG代码格式化为<img src="/UploadFiles/2021-04-02/XXX">
Function FixImg(sString) Dim sReallyDo, regEx, iReallyDo Dim oMatches, cMatch Dim tStartTime, tEndTime If IsNull(sString) Then FixImg = "" Exit Function End If sReallyDo = sString On Error Resume Next sReallyDo = Replace(sReallyDo, vbCr, " ") sReallyDo = Replace(sReallyDo, vbLf, " ") sReallyDo = Replace(sReallyDo, vbTab, " ") sReallyDo = Replace(sReallyDo, "<img ", vbCrLf & "<img ", 1, -1, 1) sReallyDo = Replace(sReallyDo, "/>", " />", 1, -1, 1) sReallyDo = ReplaceAll(sReallyDo, "= ", "=", True) sReallyDo = ReplaceAll(sReallyDo, "> ", ">", True) sReallyDo = Replace(sReallyDo, "><", ">" & vbCrLf & "<") sReallyDo = Trim(sReallyDo) On Error GoTo 0 Set regEx = New RegExp regEx.IgnoreCase = True regEx.Global = True '//去除onclick,onload等脚本 regEx.Pattern = "\s[on].+""|\'])(.*" sReallyDo = regEx.Replace(sReallyDo, "") '//将SRC不带引号的图片地址加上引号 regEx.Pattern = "<img.*""\'\s][^\""\'\s>]*).*" sReallyDo = regEx.Replace(sReallyDo, "<img src="/UploadFiles/2021-04-02/">上面的代码确实写得不错,原理也可以参考下面的代码
js过滤img里style属性
var str = "<img style='ddddddddd'>" str = str.replace(/<img[^>]*>/gi, function (match, capture) { return match.replace(/style\s*"])[\s\S]*"htmlcode">var is=document.images; for(var i=0,len=is.length;i<len;i++){ is[i].style.cssText="" }
相思资源网 Design By www.200059.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
相思资源网 Design By www.200059.com
暂无ASP删除img标签的style属性只保留src的正则函数的评论...