ASP去除img标签style属性只保留src
‘功能:将IMG代码格式化为格式,只保留SRC属性,去掉IMG标签的其他属性。
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, "", " />", 1, -1, 1) sReallyDo = ReplaceAll(sReallyDo, "= ", "=", True) sReallyDo = ReplaceAll(sReallyDo, "> ", ">", True) sReallyDo = Replace(sReallyDo, ">" & vbCrLf & "]*).*?>" sReallyDo = regEx.Replace(sReallyDo, "") '//正则匹配图片SRC地址 regEx.Pattern = "" sReallyDo = regEx.Replace(sReallyDo, "") FixImg = sReallyDo End Function
上面的代码确实写得不错,原理也可以参考下面的代码
js过滤img里style属性
var str = "" str = str.replace(/]*>/gi, function (match, capture) { return match.replace(/styles*?=s*?([‘"])[sS]*?1/ig, '') })) console.log(str)
不是替换直接通过js设置
var is=document.images; for(var i=0,len=is.length;i
到此这篇关于ASP删除img标签的style属性只保留src的正则函数的文章就介绍到这了,更多相关ASP去除img的style属性内容请搜索IT俱乐部以前的文章或继续浏览下面的相关文章希望大家以后多多支持IT俱乐部!