如何使用JavaScript搜索并显示area元素的href属性中的路径名部分?

原创
ithorizon 5个月前 (10-19) 阅读数 40 #HTML

要在 JavaScript 中获取某个区域的 href 属性的路径名部分,请使用 pathname 属性。

示例

您可以尝试运行以下代码来显示路径名部分。

<!DOCTYPE html>
<html>
   <body>
      <img src = "/images/html.gif" alt = "HTML Map" border = "0" usemap = "#html"/>
      <map name = "html">
         <area id="myarea" shape = "circle" coords = "154,150,59" href = "about.htm" target = "_self" >
      </map>
      <script>
         var x = document.getElementById("myarea").pathname;
         document.write("<br>Pathname: "+x);
      </script>
   </body>
</html>

以上就是如何使用JavaScript搜索并显示area元素的href属性中的路径名部分?的详细内容,更多请关注IT视界其它相关文章!



热门