<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