HTML DOM Link type 屬性
Link type 屬性設定/返回連結文件的型別。
語法
語法如下 −
- 返回 type 屬性的值
linkObject.type
- 將 type 設定為有效的值
linkObject.type = value
注意: 有效值包括 “text/javascript”、“text/css”、“image/gif” 等。
示例
我們來看一下 Link type 屬性的一個示例 −
<!DOCTYPE html>
<html>
<head>
<title>Link type</title>
<link id="extStyle" rel="stylesheet" href="style.css" type="myStyle">
</head>
<body>
<form>
<fieldset>
<legend>Link-type</legend>
<input type="button" value="Correct Type" onclick="correctType()">
<div id="divDisplay"></div>
</fieldset>
</form>
<script>
var divDisplay = document.getElementById("divDisplay");
var extStyle = document.getElementById("extStyle");
divDisplay.textContent = 'The linked document type: '+extStyle.type+' is not compatible';
function correctType(){
extStyle.type = 'text/css';
divDisplay.textContent = 'Congrats! The linked document type: '+extStyle.type+' is compatible';
}
</script>
</body>
</html>在上面的示例中,‘style.css’ 包含 −
form {
width:70%;
margin: 0 auto;
text-align: center;
}
* {
padding: 2px;
margin:5px;
}
input[type="button"] {
border-radius: 10px;
}輸出
將生成以下輸出 −
在單擊‘正確型別’按鈕之前 −

單擊‘正確型別’按鈕之後 −

廣告
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP