【Javascript】javascript學習 三十四 JavaScript 映像地圖

來源:互聯網
上載者:User
文章目錄
  • 執行個體

映像地圖指的是帶有可點擊地區的映像。

執行個體
簡單的 HTML 影像地圖

本例示範一幅沒有添加 JavaScript 的影像地圖。

添加了 JavaScript 的影像地圖

本例示範一幅添加了 JavaScript 的影像地圖,當滑鼠浮動於某個熱點上時,會調用 JavaScript 函數來顯示熱點所對應的星球的簡介。
JavaScript 映像地圖

我們已經從 HTML 教程中瞭解到,映像地圖是帶有可點擊地區的映像。通常情況下,每個地區是一個相關的超級連結。單擊某個地區,就回到達相關的連結。

執行個體

下面的例子示範如何建立帶有可點擊地區的 html 映像地圖:

<img src ="planets.gif" width ="145" height ="126" alt="Planets"usemap ="#planetmap" /><map id ="planetmap" name="planetmap"><area shape ="rect" coords ="0,0,82,126" href ="sun.htm" target ="_blank"  alt="Sun" /><area shape ="circle" coords ="90,58,3" href ="mercur.htm" target ="_blank"  alt="Mercury" /><area shape ="circle" coords ="124,58,8" href ="venus.htm" target ="_blank"  alt="Venus" /></map> 

結果

添加 JavaScript

我們可向映像地圖內部的 <area> 標籤添加(能調用JavaScript的)事件。<area> 標籤支援以下事件:onClick、onDblClick、onMouseDown、onMouseUp、onMouseOver、onMouseMove、onMouseOut、onKeyPress、onKeyDown、onKeyUp、onFocus和onBlur。

這是添加了 JavaScript 的上面的例子:

<html><head><script type="text/javascript">function writeText(txt){document.getElementById("desc").innerHTML=txt}</script></head><body><img src="planets.gif" width="145" height="126"alt="Planets" usemap="#planetmap" /><map id ="planetmap" name="planetmap"><area shape ="rect" coords ="0,0,82,126"onMouseOver="writeText('The Sun and the gas giantplanets like Jupiter are by far the largest objectsin our Solar System.')"href ="sun.htm" target ="_blank" alt="Sun" /><area shape ="circle" coords ="90,58,3"onMouseOver="writeText('The planet Mercury is verydifficult to study from the Earth because it isalways so close to the Sun.')"href ="mercur.htm" target ="_blank" alt="Mercury" /><area shape ="circle" coords ="124,58,8"onMouseOver="writeText('Until the 1960s, Venus wasoften considered a twin sister to the Earth becauseVenus is the nearest planet to us, and because thetwo planets seem to share many characteristics.')"href ="venus.htm" target ="_blank" alt="Venus" /></map> <p id="desc"></p></body></html>
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.