Đối tượng bản đồ DOM HTML trong HTML đại diện cho phần tử.
Cú pháp
Sau đây là cú pháp -
Tạo phần tử
var mapObject = document.createElement(“MAP”)
Thuộc tính
Đây, “mapObject” có thể có các bộ sưu tập &thuộc tính sau -
| Bộ sưu tập / Thuộc tính | Mô tả |
|---|---|
| khu vực | Nó trả về một bộ sưu tập của tất cả |
| hình ảnh | Nó trả về một tập hợp tất cả |
| tên | Nó đặt / trả về giá trị của thuộc tính name cho phần tử |
Ví dụ
Hãy để chúng tôi xem một ví dụ cho Các khu vực trên bản đồ bộ sưu tập -
<!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> Đầu ra
Điều này sẽ tạo ra kết quả sau -
Trước khi nhấp vào ‘Áp dụng liên kết’ nút -
Sau khi nhấp vào ‘Áp dụng liên kết’ nút -