取得第一個匹配元素的html內(nèi)容。這個函數(shù)不能用于XML文檔。但可以用于XHTML文檔。
html()
取得第一個匹配元素的html內(nèi)容。這個函數(shù)不能用于XML文檔。但可以用于XHTML文檔。
Get the html contents of the first matched element. This property is not available on XML documents (although it will work for XHTML documents).
返回值
String
示例
復(fù)制代碼 代碼如下:
HTML 代碼:
<div><p>Hello</p></div>
jQuery 代碼:
$("div").html();
結(jié)果:
Hello
html(val)
設(shè)置每一個匹配元素的html內(nèi)容。這個函數(shù)不能用于XML文檔。但可以用于XHTML文檔。
Set the html contents of every matched element. This property is not available on XML documents (although it will work for XHTML documents).
返回值
jQuery
參數(shù)
val (String) : 用于設(shè)定HTML內(nèi)容的值
示例
復(fù)制代碼 代碼如下:
HTML 代碼:
<div></div>
jQuery 代碼:
$("div").html("<p>Hello Again</p>");
結(jié)果:
[ <div><p>Hello Again</p></div> ]
新聞熱點
疑難解答
圖片精選