Eric's Blog

有需求才有进步

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

image-map是一张带可点击区域的图片。
————————————————————————–
HTML Image Maps

image-map是一张带可点击区域的图片,通常每一个区域是一个超级链接,点击这个区域可以访问相应的链接。

例子

<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>

效果演示

Planets

Sun Mercury Venus

增加一些JavaScript代码

我们可以在image map的
标签上增加一些事件来调用JavaScript的函数。
标签支持的事件有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 giant
            planets like Jupiter are by far the largest objects
            in our Solar System.')"
            href ="sun.htm" target ="_blank" alt="Sun" />
            <area shape ="circle" coords ="90,58,3"
            onMouseOver="writeText('The planet Mercury is very
            difficult to study from the Earth because it is
            always 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 was
            often considered a twin sister to the Earth because
            Venus is the nearest planet to us, and because the
            two planets seem to share many characteristics.')"
            href ="venus.htm" target ="_blank" alt="Venus" />
            </map>
            <p id="desc"></p>
            </body>
            </html>
posted on 2008-02-06 22:29  Eric.Chai  阅读(539)  评论(0编辑  收藏  举报