Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> HTML

Thuộc tính type của Link trong HTML DOM

Thuộc tính type của Link trong HTML DOM thiết lập/trả về loại của tài liệu được liên kết.

Cú pháp

Trả về giá trị thuộc tính type:

linkObject.type

Thiết lập type thành 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ụ

Ví dụ minh họa thuộc tính 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="Sửa loại" 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; }

Kết quả

Trước khi nhấn nút 'Sửa loại':

Thuộc tính type của Link trong HTML DOM

Sau khi nhấn nút 'Sửa loại':

Thuộc tính type của Link trong HTML DOM