HTML DOM ลิงค์แอตทริบิวต์ href
ความหมายและการใช้งาน
แอตทริบิวต์ href เป็นอ่านและเขียนได้ชุดสตริงหรือส่งกลับ URL ที่สมบูรณ์ของเอกสารที่แสดงอยู่ในปัจจุบัน
ไวยากรณ์
ตั้งค่าแอตทริบิวต์ href:
linkObject.href="URL"
กลับแอตทริบิวต์ href:
linkObject.href
สนับสนุนเบราว์เซอร์
เบราว์เซอร์ที่สำคัญทั้งหมดสนับสนุนแอตทริบิวต์ href
ตัวอย่าง
ตัวอย่าง
คลิกที่ปุ่มเพื่อสลับ Style Sheets:
<! DOCTYPE html>
<html>
<head>
<Meta charset = "UTF-8">
<title> กวดวิชานี้ (w3big.com) </ title>
<link id = "Style1" rel = "สไตล์ชีต" type = "text / css ที่" href = "style1.css">
<script>
ฟังก์ชั่น displayResult () {
document.getElementById ( "Style1") href = "style2.css" .;
}
</ script>
</ head>
<body>
<h1> หน้าแรกของฉัน </ h1>
<ปุ่ม type = "ปุ่ม" onclick = "displayResult ()"> เพื่อสลับแผ่นสไตล์ </ ปุ่ม>
</ body>
</ html>
<html>
<head>
<Meta charset = "UTF-8">
<title> กวดวิชานี้ (w3big.com) </ title>
<link id = "Style1" rel = "สไตล์ชีต" type = "text / css ที่" href = "style1.css">
<script>
ฟังก์ชั่น displayResult () {
document.getElementById ( "Style1") href = "style2.css" .;
}
</ script>
</ head>
<body>
<h1> หน้าแรกของฉัน </ h1>
<ปุ่ม type = "ปุ่ม" onclick = "displayResult ()"> เพื่อสลับแผ่นสไตล์ </ ปุ่ม>
</ body>
</ html>
ลอง»
การเชื่อมโยงวัตถุ