Thuộc tính Loại liên kết đặt / trả về loại tài liệu được liên kết.
Cú pháp
Sau đây là cú pháp -
- Trả về loại giá trị thuộc tính
linkObject.type
- Cài đặt loại thành một giá trị hợp lệ
linkObject.type = value
LƯU Ý - các giá trị hợp lệ bao gồm "text / javascript", "text / css", "image / gif", v.v.
Ví dụ
Hãy để chúng tôi xem một ví dụ về Loại liên kết tài sản -
<!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> Trong ví dụ trên ‘style.css’ chứa -
form {
width:70%;
margin: 0 auto;
text-align: center;
}
* {
padding: 2px;
margin:5px;
}
input[type="button"] {
border-radius: 10px;
} Đầu ra
Điều này sẽ tạo ra kết quả sau -
Trước khi nhấp vào 'Loại đúng' nút -
Sau khi nhấp vào 'Loại đúng' nút -