87,907
社区成员
发帖
与我相关
我的任务
分享
var str = 'xxxxx<p>123</p>ggg <img src="zxc.jpg"> gg <div id="sd" class=asd align=center style="color: #ff9;">4444<a href="http://xxxxxxxxx" title="abc" target="_blank">666</a>888</div>';
str=str.replace(/(<\/?)([a-z]+)(\s[\w\W]*?)?(>)/ig,function(s0,s1,s2,s3,s4) {
if (!/^(img|a|table|tr|th|td|tbody|thead|div)$/.test(s2))
return "";
if(s3)
s3 = s3.replace(/\s+(id|class|style)(=(([\"\']).*?\4|\S*))?/g,"");
return s1+s2+(s3||"")+s4;
});
alert(str);