使用 getElementById()

  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4. function getValue()
  5. {
  6. var x=document.getElementById("myHeader")
  7. alert(x.innerHTML)
  8. }
  9. </script>
  10. </head>
  11. <body>
  12.  
  13. <h1 id="myHeader" onclick="getValue()">这是标题</h1>
  14. <p>点击标题,会提示出它的值。</p>
  15.  
  16. </body>
  17. </html>