2015-11-05 39 views
1

我要追加在DIV text/html的標籤不改變它的意義。 所以當我追加
<a>This is not anchor </a>, 應該顯示<a>This is not anchor </a> 但它顯示超鏈接內div - >這不是錨點。
我怎樣才能做到這一點使用$("#mydiv").append("<a>This is not anchor</a>"). 請幫助。追加/顯示HTML,因爲它是

+0

閱讀上的HTML實體。尤其是'<'和''>。 –

回答

0

好像你需要將其追加爲文本本身。然後像這樣使用,

$("#mydiv").text($("#mydiv").text()+"<a>This is not anchor</a>") 
0

.append()將內容附加爲html而不是文本。而你需要的內容以文本追加。您可以使用回調函數的.text()來實現這一目標:

$("#mydiv").text(function(i,o){ 
    return o + "<a>This is not anchor</a>"; 
}); 

Working Demo