1、问题背景:
查找到h1-h6,并遍历它们,打印出内容
2、实现代码:
<!doctype html> <html> <head> <meta charset="utf-8" /> <title>查找标题</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、运行效果图:
相关推荐:
如何正确使用标题元素、段落和强制换行_基础教程
jquery获取元素的方法总结
javascript获取元素的方法与属性的实例分析
以上就是jquery获取h1-h6标题元素值方法实例的详细内容。
