Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> JavaScript

Cách tìm văn bản thay thế (alt) của vùng image-map trong JavaScript?

Sử dụng thuộc tính alt của phần tử <area> để lấy văn bản thay thế.

Ví dụ

<!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?id=company" alt="Team" target="_self">
    </map>
    <script>
      var x = document.getElementById("myarea").alt;
      document.write("<br>Văn bản thay thế: " + x);
    </script>
  </body>
</html>