2015-06-14 77 views
0

我在使這項工作正常工作時遇到了一些麻煩。用jQuery替換文本問題

我有以下結構

<nav class="breadcrumb" > 
    <a href="http://example.com">Home</a>  
     ">"   
    <a href="http://example.com/category/Mens/">Mens</a>   
     "> Mens Clothing"  
</nav> 

其中輸出到麪包屑:

Home>Mens>Mens Clothing 

我想:

Home>Mens>Clothing 

而且我更換麪包屑的最後一部分代碼:

$(".breadcrumb").text(function(){ 
    return $(this).text().replace("Mens Clothing", "Clothing"); 
}) 

我的問題是我的代碼刪除鏈接,只是給我留下了」

<nav class="breadcrumb" > 
    "Home>Mens>clothing" 
</nav> 

沒有聯繫。

不知道爲什麼。請幫助

+2

你爲什麼不使它服務器端呢?如果你不想要男士服裝,你爲什麼首先要設置它? –

回答

2

嘗試使用的html()代替text()

$(".breadcrumb").html(function(){ 
    return $(this).html().replace("Mens Clothing", "Clothing"); 
}); 
+0

賓果!謝謝。我會查找兩者之間的差異,儘管我已經可以猜測了。謝謝!!!! –

0

根據您當前的HTML,你可以改變你的方法來

​​