<a href="http://www.website.com/something" title="Show Profile">Mentalist</a>
每当一个超链接有“显示简介”标题我想删除的超链接,并只用文本替换它。删除超链接但保留文字?
所以不是
<a href="http://www.website.com/something" title="Show Profile">Mentalist</a>
我想只有Mentalist
。
不知道如何解决?
<a href="http://www.website.com/something" title="Show Profile">Mentalist</a>
每当一个超链接有“显示简介”标题我想删除的超链接,并只用文本替换它。删除超链接但保留文字?
所以不是
<a href="http://www.website.com/something" title="Show Profile">Mentalist</a>
我想只有Mentalist
。
不知道如何解决?
这样做:
<a href="http://www.website.com/something" title="Show Profile">Mentalist</a>
<a href="http://www.website.com/something" title="Something Else">Mentalist</a>
<script type="text/javascript">
$("a[title='Show Profile']").each(function(){
$(this).replaceWith($(this).text());
});
</script>
应该只替换第一个链接。
DanielB在这里提供了一个更好的解决方案:http://stackoverflow.com/questions/6188277/remove-hyperlink-but-keep-text/6188344#6188344 – rciq 2011-05-31 13:38:19
为此对多个类别的链接,
$("a.className1, a.className2").contents().unwrap();
解包()是相当整洁。为了完整起见,下面是另一个也应该起作用的解决方案:$(“a [title ='Show Profile']”)。replaceWith(function(){return $(this).contents();}); – muffinista 2011-05-31 13:35:02
非常好的解决方案 – AVH 2013-04-17 22:15:30
真的很聪明! +10 – 2016-12-22 14:12:39