简体   繁体   English

Jquery onclick与地图区域

[英]Jquery onclick with map area

I am not sure what I am doing wrong. 我不确定我做错了什么。

I am using an image map that needs to click an area then change an image, the text and the header. 我正在使用需要单击某个区域的图像映射,然后更改图像,文本和标题。 I have followed as many tutorials as I can, but it isn't working. 我尽可能多地遵循了教程,但它无法正常工作。

This is the method I am currently using: 这是我目前使用的方法:

CSS: CSS:

#SafetyStopTitle {display:show}
#SafetyStopText {display:show;}
#SafetyStopImg {display:show;}
#PenStyleActivationTitle {display:none;}
#PenStyleActivationText {display:none;}
#PenStyleActivationImg {display:none;}
#ErgonomicGripText {display:none;}
#ErgonomicGripTitle {display:none;}
#ErgonomicGripImg {display:none;}
#BladeActivationTitle {display:none;}
#BladeActivationText {display:none;}
#BladeActivationImg {display:none;}
#TaperedTipTitle {display:none;}
#TaperedTipText {display:none;}
#TaperedTipImg {display:none;}
#SafetySutureGrooveTitle {display:none;}
#SafetySutureGrooveText {display:none;}
#SafetySutureGrooveImg {display:none;}
#BladeAvailabilityTitle {display:none;}
#BladeAvailabilityText {display:none;}
#BladeAvailabilityImg {display:none;}
#SafetyStopArea{}
#PenStyleActivationArea{}
#ErgonomicGripArea{}
#BladeActivationArea{}
#TaperedTipArea{}
#SafetySutureGrooveArea{}
#BladeAvailabilityArea{}

JQuery JQuery的

$("PenStyleActivationArea").click(function(){
    $("SafetyStopTitle").css(“display”, “none”);
    $("SafetyStopText").css(“display”, “none”);
    $("SafetyStopImg").css(“display”, “none”);
    $("PenStyleActivationTitle").css(“display”, “show”);
    $("PenStyleActivationText").css(“display”, “show”);
    $("PenStyleActivationImg").css(“display”, “show”);
    $("ErgonomicGripText").css(“display”, “none”);
    $("ErgonomicGripTitle").css(“display”, “none”);
    $("ErgonomicGripImg").css(“display”, “none”);
    $("BladeActivationTitle").css(“display”, “none”);
    $("BladeActivationText").css(“display”, “none”);
    $("BladeActivationImg").css(“display”, “none”);
    $("TaperedTipTitle").css(“display”, “none”);
    $("TaperedTipText").css(“display”, “none”);
    $("TaperedTipImg").css(“display”, “none”);
    $("SafetySutureGrooveTitle").css(“display”, “none”);
    $("SafetySutureGrooveText").css(“display”, “none”);
    $("SafetySutureGrooveImg").css(“display”, “none”);
    $("BladeAvailabilityTitle").css(“display”, “none”);
    $("BladeAvailabilityText").css(“display”, “none”);
    $("BladeAvailabilityImg").css(“display”, “none”);
});

Map: 地图:

  <map id="imgmap201310792213" name="imgmap201310792213"> 
    <area title="" alt="Safety Stop" coords="533,94,14" shape="circle" href="#/SafetyStop" /> 
    <area title="" alt="Pen Style Activation" coords="447,179,14" shape="circle" href="#/PenStyleActivation" /> 
    <area title="" alt="Broad Sturdy Ergonomic Grip" coords="386,219,14" shape="circle" href="#/ErgonomicGrip" /> 
    <area title="" alt="No Look, No Reposition, Passive or Active Blade Retraction" coords="232,312,15" shape="circle" href="#/BladeActivation" /> 
    <area title="" alt="Tapered For Better Blade Visibility" coords="170,401,16" shape="circle" href="#/TaperedTip" /> 
    <area title="" alt="Safety Suture Trimming Groove" coords="136,413,14" shape="circle" href="#/SafetySutureGroove" /> 
    <area title="" alt="Blade Availability" coords="107,431,15" shape="circle" href="#/BladeAvailability" /> 
    <area id="SafetyStopArea" coords="384,85,474,97" shape="rect" href="#/SafetyStop" /> 
    <area id="PenStyleActivationArea" coords="473,171,554,200" shape="rect" href="#/PenStyleActivation" /> 
    <area id="ErgonomicGripArea" coords="242,136,352,160" shape="rect" href="#/ErgonomicGrip" /> 
    <area id="BladeActivationArea" coords="12,235,187,279" shape="rect" href="#/BladeActivation" /> 
    <area id="BladeAvailabilityArea" coords="21,308,144,368" shape="rect" href="#/BladeAvailability" /> 
    <area id="TaperedTipArea"coords="240,387,371,415" shape="rect" href="#/TaperedTip" /> 
    <area id="SafetySutureGrooveArea" coords="141,442,261,468" shape="rect" href="/#/SafetySutureGroove" /> 
  </map>

here is the fiddle am using: http://jsfiddle.net/timlcooley/sax66/2/ 这是使用的小提琴: http//jsfiddle.net/timlcooley/sax66/2/

Thanks for the help. 谢谢您的帮助。 I am sure there is a faster way of doing this :-/ 我相信有更快的方法: - /

Here look http://jsfiddle.net/sax66/4/ . 这里看http://jsfiddle.net/sax66/4/ Clicking on those 2 areas the img below gets changed. 点击这两个区域,下面的img会发生变化。 Hope that was your purpose :) 希望那是你的目的:)

Anyway display:show isn't a CSS property, you may want to use display:inline or some other property which I suggest you to learn. 无论如何display:show不是CSS属性,你可能想使用display:inline或其他一些我建议你学习的属性。

As you may also see, I made your JS more simple and less repetitive. 正如您可能也看到的那样,我使您的JS更简单,重复性更低。

IMPORTANT! 重要! You used in your js something like 你在js中使用了类似的东西

$('SafetyStopTitle')..

This is wrong. 这是错的。

Why? 为什么? This way, jQuery will look for the <SafetyStopTitle> TAG and NOT FOR the id="SafetyStopTitle" so you have to use # before SafetyStopTitle . 这样,jQuery将查找<SafetyStopTitle> TAG而不是id="SafetyStopTitle"因此您必须在SafetyStopTitle之前使用#

If you want to use an element with an ID you have to use: 如果要使用具有ID的元素,则必须使用:

$('#SafetyStopTitle')..

Or, if you want to use and element with a CLASS, you have to use: 或者,如果要使用带有CLASS的元素,则必须使用:

$('.SafetyStopTitle')..

hmm .... 嗯....

$("#SafetyStopTitle").css("display", "none");

etc. 等等

and there is no show in display: 并且show中没有display:

#SafetyStopTitle {display:block /* or whatever */}

Your Updated FIDDLE with no errors. 您更新的FIDDLE没有错误。

Jquery always look for ids by using # and for classes by . Jquery总是通过使用#和for来查找id . . So, you should prep-pend # before all the ids. 所以,你应该在所有id之前预备# For eg 例如

replace $('eleid') by $('#ele-id')

You have to add two divs for which you're assigning the clicks callbacks. 您必须添加两个div,您要为其分配clicks回调。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM