我試圖在加載HTML的區域我的網頁上,我可以加載純文本的所有行,見下面的例子:的jQuery加載HTML
function(msg) {
// Replace the div's content with the page method's return.
$("#CategoryExtension").text(msg);
}
然而,當我嘗試包括HTML內容會顯示它原樣,並在內容上添加引號。
我該如何克服這一點?
我試圖在加載HTML的區域我的網頁上,我可以加載純文本的所有行,見下面的例子:的jQuery加載HTML
function(msg) {
// Replace the div's content with the page method's return.
$("#CategoryExtension").text(msg);
}
然而,當我嘗試包括HTML內容會顯示它原樣,並在內容上添加引號。
我該如何克服這一點?
HTML?嘗試
$("#CategoryExtension").html(msg);
記得,有文本()和HTML()
文本()是一樣的Text屬性和HTML()是innerHTML屬性,使用div時你應該改變innerHTML屬性,就像
document.getElementById('myDiv').innerHTML = 'This is <strong>my bold text</strong>.';
在jQuery wo RLD你做到的一樣
$("#myDiv").html('This is <strong>my bold text</strong>.');
它有助於瞭解關於HTML和Javascript :)
一點你需要使用html()
。例如:
$("#CategoryExtension").html("<span>Hello</span>");
另外,請檢查jQuery Documentation以熟悉的API。它會幫助你很多。