ออบเจ็กต์แมป HTML DOM ใน HTML แสดงถึง ธาตุ
ไวยากรณ์
ต่อไปนี้เป็นไวยากรณ์ -
การสร้าง องค์ประกอบ
var mapObject = document.createElement(“MAP”)
คุณสมบัติ
ที่นี่ “mapObject” สามารถมีคอลเลกชันและคุณสมบัติดังต่อไปนี้ -
| คอลเลกชัน/ คุณสมบัติ | คำอธิบาย |
|---|---|
| พื้นที่ | ส่งคืนคอลเล็กชันของ ทั้งหมด องค์ประกอบ |
| รูปภาพ | ส่งคืนคอลเลกชันของทั้งหมด |
| ชื่อ | มันตั้งค่า/ส่งคืนค่าของแอตทริบิวต์ชื่อสำหรับองค์ประกอบ |
ตัวอย่าง
ให้เราดูตัวอย่างสำหรับพื้นที่แผนที่ คอลเลกชัน -
<!DOCTYPE html>
<html>
<head>
<title>Map areas collection</title>
<style>
form {
width:70%;
margin: 0 auto;
text-align: center;
}
* {
padding: 2px;
margin:5px;
}
input[type="button"] {
border-radius: 10px;
}
</style>
</head>
<body>
<form>
<fieldset>
<legend>Map-areas-collection</legend>
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/f/fb/New7Wonders.jpg/276px-New7Wonders.jpg" width="250" height="150" usemap="#7Wonders">
<map id="WonderWorld" name="7Wonders">
</map>
<div id="divDisplay"></div>
<input type="button" value="Apply Link" onclick="myWonder()">
</fieldset>
</form>
<script>
function myWonder() {
var divDisplay = document.getElementById("divDisplay");
var newArea = document.createElement("AREA");
newArea.setAttribute("href", "https://en.wikipedia.org/wiki/Giza_pyramid_complex");
newArea.setAttribute("shape", "rect");
newArea.setAttribute("coords", "120,10,10,40");
document.getElementById("WonderWorld").appendChild(newArea);
divDisplay.textContent = "Link was applied, hover and click on pyramid of giza.";
}
</script>
</body>
</html> ผลลัพธ์
สิ่งนี้จะสร้างผลลัพธ์ต่อไปนี้ -
ก่อนคลิก 'ใช้ลิงก์' ปุ่ม −

หลังจากคลิก 'ใช้ลิงก์' ปุ่ม −
