本文實例講述了jQuery實現(xiàn)獲取h1-h6標(biāo)題元素值的方法。分享給大家供大家參考,具體如下:
1、問題背景:
查找到h1-h6,并遍歷它們,打印出內(nèi)容
2、實現(xiàn)代碼:
<!DOCTYPE html><html> <head> <meta charset="utf-8" /> <title>查找標(biāo)題</title> <script type="text/javascript" src="jquery-1.7.2.min.js" ></script> <script> $(function(){ //查找h1-h6 $(":header").each(function(){ $(this).click(function(event){ console.info(event.target.innerText); console.log(event.currentTarget.innerHTML); }); }); }); </script> </head> <body> <h1>Hello H1</h1> <h2>Hello H2</h2> <h3>Hello H3</h3> <h4>Hello H4</h4> <h5>Hello H5</h5> <h6>Hello H6</h6> </body></html>3、運行效果圖:

更多關(guān)于jQuery相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《jQuery form操作技巧匯總》、《jQuery操作json數(shù)據(jù)技巧匯總》、《jQuery常用插件及用法總結(jié)》、《jQuery擴(kuò)展技巧總結(jié)》、《jQuery表格(table)操作技巧匯總》及《jquery選擇器用法總結(jié)》
希望本文所述對大家jQuery程序設(shè)計有所幫助。
新聞熱點
疑難解答