查找链接的 rel 属性的值

  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4.  
  5. <p><a id="myAnchor" rel="nofollow" href="https://www.yousite.com/">yousite</a></p>
  6.  
  7. <p>单击按钮以显示上面链接的 rel 属性的值。</p>
  8.  
  9. <button onclick="myFunction()">试一试</button>
  10.  
  11. <p id="demo"></p>
  12.  
  13. <script>
  14. function myFunction() {
  15. var x = document.getElementById("myAnchor").rel;
  16. document.getElementById("demo").innerHTML = x;
  17. }
  18. </script>
  19.  
  20. </body>
  21. </html>