jQuery删除所有HTML标签除了Anchors [英] jQuery remove all HTML tags EXCEPT Anchors
本文介绍了jQuery删除所有HTML标签除了Anchors的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
this.html(this.html()。replace(/ \x3C \x2F?[^ \x3E] + \x3E / gi,''));
但是,我想按照if子句的说法来说,
IF(this.tag =< a){
什么也不做
} ELSE {
删除标记
}
我不认为有人有任何想法吗?
:我想我可能要做一个FOR EACH循环......我想...... [/编辑]
^。^
解决方案
this.html(this.html()。replace(/< \ /?([bz] +)[^>]> / gi,function(match,tag){
return( tag ===a)?match:;
}));
如果您正在考虑放置a标签,请将正则表达式从 [az]
至 [bz]
Currently, I have this line:
this.html(this.html().replace(/\x3C\x2F?[^\x3E]+\x3E/gi, ''));
But, I would like something along the lines of an "if clause" to say,
IF (this.tag = "<a") {
do nothing
} ELSE {
remove tag
}
I don't suppose anyone has any ideas?
[EDIT]: I think I may have to do a "FOR EACH" loop... I think.... [/EDIT]
^.^
解决方案
this.html(this.html().replace(/<\/?([b-z]+)[^>]*>/gi, function(match, tag) {
return (tag === "a") ? match : "";
}));
If you are looking at leaving the "a" tags in place, change the regular expression from [a-z]
to [b-z]
这篇关于jQuery删除所有HTML标签除了Anchors的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文