【问题标题】:Image map onclick problems图片映射onclick问题
【发布时间】:2015-01-09 16:58:24
【问题描述】:

大家好,我的代码有问题:

$("#gotobikeblue").click(function(){
           
           $("#bikeblue").show();
           $("#motor").hide();
           $("#wheel").hide();

           
        return false;
    });
    
    $("#gotomotor").click(function(){
           
           $("#bikeblue").hide();
           $("#motor").show();
           $("#wheel").hide();
   
           
        return false;
    });
    
    $("#gotowheel").click(function(){
           
           $("#bikeblue").hide();
           $("#motor").hide();
           $("#wheel").show();
   
           
        return false;
    });
#bikeblue
{
display:none;
}

#wheel
{
display:none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<img src="http://i62.tinypic.com/2l8jmzo.jpg" alt="" usemap="#motor" id="motor"/>
<map  id="motor" name="motor">
<area id="gotobikeblue" alt="" title="" href="" shape="rect" coords="1135,13,1261,123" style="outline:none;" target="_self"     />
<area id="gotowheel" alt="" title="" href="" shape="rect" coords="1110,874,1265,997" style="outline:none;" target="_self"     />
</map>


<img src="http://i62.tinypic.com/14kv6zo.jpg" alt="" usemap="#bikeblue" id="bikeblue"/> 
<map id="bikeblue" name="bikeblue">
<area id="gotomotor" alt="" title="" href="" shape="rect" coords="10,9,103,92" style="outline:none;" target="_self"     />
<area id="gotowheel" alt="" title="" href="" shape="rect" coords="899,666,1010,756" style="outline:none;" target="_self"     />
</map>


<img src="http://i58.tinypic.com/2qvw12x.jpg" alt="" usemap="#wheel" id="wheel"/> 
<map id="wheel" name="wheel">
<area id="gotomotor" alt="" title="" href="" shape="rect" coords="13,12,164,109" style="outline:none;" target="_self"     />
<area id="gotobikeblue" alt="" title="" href="" shape="rect" coords="35,130,127,210" style="outline:none;" target="_self"     />
</map>

为什么点击 2-3 次后页面会重新加载? 我需要页面不重新加载并单击缩略图让我看到相应的图像。 但是,如果将此代码与两个图像一起使用,我不会遇到问题。当图像超过两个时,问题就来了。



不要在这里运行代码,它在这里不起作用。

【问题讨论】:

  • 哇,我大概有 8 年多没见过图像地图了。

标签: javascript html image dictionary imagemap


【解决方案1】:

这似乎与具有相同 ID 的多个元素有关(无效的 HTML)。

如果我将重复的 ID 更改为类,页面将不再为我重新加载:

$(".gotobikeblue").click(function(){
    $("#bikeblue").show();
    $("#motor").hide();
    $("#wheel").hide();

    return false;
});

$(".gotomotor").click(function(){
    $("#bikeblue").hide();
    $("#motor").show();
    $("#wheel").hide();

    return false;
});

$(".gotowheel").click(function(){
    $("#bikeblue").hide();
    $("#motor").hide();
    $("#wheel").show();

    return false;
});

还有 HTML:

<img src="http://i62.tinypic.com/2l8jmzo.jpg" alt="" usemap="#motor" id="motor"/>
<map  id="motor" name="motor">
<area class="gotobikeblue" alt="" title="" href="" shape="rect" coords="1135,13,1261,123" style="outline:none;" target="_self"     />
<area class="gotowheel" alt="" title="" href="" shape="rect" coords="1110,874,1265,997" style="outline:none;" target="_self"     />
</map>


<img src="http://i62.tinypic.com/14kv6zo.jpg" alt="" usemap="#bikeblue" id="bikeblue"/> 
<map id="bikeblue" name="bikeblue">
<area class="gotomotor" alt="" title="" href="" shape="rect" coords="10,9,103,92" style="outline:none;" target="_self"     />
<area class="gotowheel" alt="" title="" href="" shape="rect" coords="899,666,1010,756" style="outline:none;" target="_self"     />
</map>


<img src="http://i58.tinypic.com/2qvw12x.jpg" alt="" usemap="#wheel" id="wheel"/> 
<map id="wheel" name="wheel">
<area class="gotomotor" alt="" title="" href="" shape="rect" coords="13,12,164,109" style="outline:none;" target="_self"     />
<area class="gotobikeblue" alt="" title="" href="" shape="rect" coords="35,130,127,210" style="outline:none;" target="_self"     />
</map>

【讨论】:

    猜你喜欢
    • 2020-02-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-24
    • 2019-01-22
    相关资源
    最近更新 更多