小码哥的IT人生

HTML DOM type 属性

JavaScript基础 2022-06-08 15:28:57小码哥的IT人生shichen

HTML DOM type 属性

定义和用法

type 属性可设置或返回被链资源的 MIME 类型。

语法

anchorObject.type=type

实例

下面的例子可返回被链资源的 MIME 类型:

<html>
<body>
<p><a id="myAnchor" type="text/html" 
href="http://www.phpcodeweb.com">phpcodeweb.com</a></p>
<script type="text/javascript">
x=document.getElementById("myAnchor");
document.write(x.type);
</script>
</body>
</html>

TIY

完整实例【取得链接的 MIME 类型】:

<html>
<body>
<p><a id="myAnchor" type="text/html" href="http://www.phpcodeweb.com">phpcodeweb.com</a></p>
<p>单击按钮以显示上面链接的 type 属性的值。</p>
<button onclick="myFunction()">试一试</button>
<p id="demo"></p>
<script>
function myFunction() {
  var x = document.getElementById("myAnchor").type;
  document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>

可以使用本站在线JavaScript测试工具测试上述代码运行效果:http://www.phpcodeweb.com/runjs.html

版权所有 © 小码哥的IT人生
Copyright © phpcodeweb All Rights Reserved
ICP备案号:苏ICP备17019232号-2  

苏公网安备 32030202000762号

© 2021-2024