HTML DOM中的Map name屬性用於設置或返回map元素的name屬性的值。此屬性指定映射圖像的名稱。此屬性與<img> usemap屬性相關聯。它在<image>和<map>元素之間創建關係。
用法:
- 它返回name屬性。
mapObject.name
- 它用於設置name屬性。
mapObject.name = name
屬性值:
- name:它擁有一個image-map的名稱。
返回值:它返回一個表示Map元素名稱的字符串值。
例:
<!DOCTYPE html>
<html>
<head>
<title>
HTML DOM Map name Property
</title>
</head>
<body>
<h2>
GeeksForGeeks
</h2>
<h3>
HTML DOM Map name Property
</h3>
<h4>Click the button</h4>
<map id = "Geeks" name = "Geeks">
<area = "rect" coords = "0, 0, 110, 100"
alt = "Geeks" href =
"https://media.geeksforgeeks.org/wp-content/uploads/a1-21.png">
<area shape = "rect" coords = "110, 0, 190, 100"
alt = "For" href =
"https://media.geeksforgeeks.org/wp-content/uploads/a1-22.png">
<area shape = "rect" coords = "190, 0, 300, 100"
alt = "GEEKS" href =
"https://media.geeksforgeeks.org/wp-content/uploads/a1-24.png">
</map>
<img src =
"https://media.geeksforgeeks.org/wp-content/uploads/a1-25.png"
width = "300" height = "100" alt="GFG" usemap = "#Geeks">
<br><br>
<button onclick = "GFG()">
Click Here!
</button>
<p id = "GEEK!"></p>
<script>
function GFG() {
var x = document.getElementById("Geeks").name;
document.getElementById("GEEK!").innerHTML = x;
}
</script>
</body>
</html>
輸出:
- 單擊按鈕之前:
- 單擊按鈕後:
範例2:
<!DOCTYPE html>
<html>
<head>
<title>
HTML DOM Map name Property
</title>
</head>
<body>
<h2>
GeeksForGeeks
</h2>
<h3>
HTML DOM Map name Property
</h3>
<h4>Click the button</h4>
<map id = "Geeks" name = "Geeks">
<area = "rect" coords = "0, 0, 110, 100"
alt = "Geeks" href =
"https://media.geeksforgeeks.org/wp-content/uploads/a1-21.png">
<area shape = "rect" coords = "110, 0, 190, 100"
alt = "For" href =
"https://media.geeksforgeeks.org/wp-content/uploads/a1-22.png">
<area shape = "rect" coords = "190, 0, 300, 100"
alt = "GEEKS" href =
"https://media.geeksforgeeks.org/wp-content/uploads/a1-24.png">
</map>
<img src =
"https://media.geeksforgeeks.org/wp-content/uploads/a1-25.png"
width = "300" height = "100" alt="GFG" usemap = "#Geeks">
<br><br>
<button onclick = "GFG()">
Click Here!
</button>
<p id = "GEEK!"></p>
<script>
function GFG() {
var x = document.getElementById("Geeks").name
= "Hello Geeks";
document.getElementById("GEEK!").innerHTML
= "The name was changed to " + x;
}
</script>
</body>
</html>
輸出:
- 單擊按鈕之前:
- 單擊按鈕後:
支持的瀏覽器:下麵列出了HTML DOM Map name屬性支持的瀏覽器:
- 穀歌瀏覽器
- IE瀏覽器
- Firefox
- Safari
- Opera
相關用法
- HTML DOM name用法及代碼示例
- HTML DOM id用法及代碼示例
- HTML DOM specified用法及代碼示例
- HTML DOM value用法及代碼示例
- HTML li value用法及代碼示例
- HTML DOM dir用法及代碼示例
- HTML DOM URL用法及代碼示例
- HTML Bdo dir用法及代碼示例
- HTML DOM accessKey用法及代碼示例
- HTML Textarea name用法及代碼示例
- HTML DOM attributes用法及代碼示例
- HTML Button name用法及代碼示例
- HTML IFrame name用法及代碼示例
- HTML Button value用法及代碼示例
- HTML DOM offsetLeft用法及代碼示例
注:本文由純淨天空篩選整理自ManasChhabra2大神的英文原創作品 HTML | DOM Map name Property。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。