当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


HTML Map name用法及代码示例


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


相关用法


注:本文由纯净天空筛选整理自ManasChhabra2大神的英文原创作品 HTML | DOM Map name Property。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。