本文實(shí)例講述了jQuery獲取標(biāo)簽文本內(nèi)容和html內(nèi)容的方法。分享給大家供大家參考。具體分析如下:
jQuery可以通過(guò)text和html方法獲取指定標(biāo)簽的文本內(nèi)容或者h(yuǎn)tml內(nèi)容
<!DOCTYPE html><html><head><script src="js/jquery.min.js"></script><script>$(document).ready(function(){ $("#btn1").click(function(){  alert("Text: " + $("#test").text()); }); $("#btn2").click(function(){  alert("HTML: " + $("#test").html()); });});</script></head><body><p id="test">This is some <b>bold</b> text in a paragraph.</p><button id="btn1">Show Text</button><button id="btn2">Show HTML</button></body></html>希望本文所述對(duì)大家的jQuery程序設(shè)計(jì)有所幫助。
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注