HTML DOM 地圖物件


HTML 中的 HTML DOM Map 物件表示 <map> 元素。

語法

以下是語法 −

建立 <map> 元素

var mapObject = document.createElement(“MAP”)

屬性

在此,“mapObject” 可包含以下集合和屬性 −

集合/屬性描述
areas返回所有 <area> 元素的集合
images返回所有 <img><object> 元素的集合
name設定/返回 <map> 元素的 name 屬性的值

示例

讓我們檢視一個 Map areas 集合的示例 −

 即時演示

<!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>

輸出

此程式碼將產生以下輸出 −

在點選 ‘應用連結’ 按鈕之前 −

在點選 ‘應用連結’ 按鈕之後 −

更新於: 31-7-2019

133 次瀏覽

開始你的職業

透過完成課程獲得認證

開始學習
廣告
© . All rights reserved.