本文實例講述了jQuery獲取標簽文本內容和html內容的方法。分享給大家供大家參考。具體分析如下:
jQuery可以通過text和html方法獲取指定標簽的文本內容或者html內容
<!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>
希望本文所述對大家的jQuery程序設計有所幫助。
新聞熱點
疑難解答