查找页面上所有链接的基准目标

  1. <html>
  2. <head>
  3. <base id="myBaseId" target="_blank"
  4. href="http://www.jishuchi.com/books/jsref/" />
  5. </head>
  6.  
  7. <body>
  8.  
  9. <p>单击按钮以显示 base 元素的 target 属性的值。</p>
  10.  
  11. <button onclick="myFunction()">试一试</button>
  12.  
  13. <p id="demo"></p>
  14.  
  15. <script>
  16. function myFunction() {
  17. var x = document.getElementById("myBaseId").target;
  18. document.getElementById("demo").innerHTML = "所有链接的基准目标是:" + x;
  19. }
  20. </script>
  21.  
  22. </body>
  23. </html>