如何在 JavaScript 中获取链接的 type 属性值?

htmljavascriptprogramming scripts

要在 JavaScript 中获取链接的 type 属性值,请使用 type 属性。type 属性用于指示文档是 html (text/html) 还是 css (text/css) 等。

示例

您可以尝试运行以下代码来获取链接的 type 属性值。

<!DOCTYPE html>
<html>
   <body>
      <p><a id="anchorid" type="text/html" target= "_blank" href="https://www.qries.com/">Qries</a></p>
      <script>
         var myVal = document.getElementById("anchorid").type;
         document.write("Value of type attribute: "+myVal);
      </script>
   </body>
</html>

相关文章