简体   繁体   English

显示/隐藏在Jquery图像映射上的工作不一致

[英]Show/hide working inconsistently on a Jquery imagemap

I'm working on an imagemap that not only is hi-lighted, but also does a show/hide on a some additional information on a Drupal site: 我正在处理一个不仅具有高亮度的图像映射,而且还在Drupal网站上的一些其他信息上显示/隐藏:

http://dev-wateraid.pantheonsite.io/where-we-work http://dev-wateraid.pantheonsite.io/where-we-work

If you hover over countries like Canada you'll see the DIV show up, but if you hover over the United States the area is hi-lighted but it doesn't trigger the show/hide -- similar with Sierra Leone, South Africa, the UK, Papua New Guinea, and a few others. 如果您将鼠标悬停在加拿大等国家/地区,就会看到DIV出现,但是如果您将鼠标悬停在美国之上,则该区域会被高亮显示,但不会触发显示/隐藏-与南非塞拉利昂,英国,巴布亚新几内亚和其他一些国家。

The code I'm using to do the show hide is: 我用来显示秀的代码是:

$('area').on({
   mouseover : function(e){
   var $this = $(this),
   $office = $('#'+$this.prop('alt'));
   $($office).removeClass("hidden");
},
   mouseout : function(e){
   var $this = $(this),
   $office = $('#'+$this.prop('alt'));
   $($office).addClass("hidden");
}
});

The image map holds the alt tag which is then used to show/hide a div: 图像映射包含alt标签,该标签随后用于显示/隐藏div:

<area coords="96,67,97,61,76,40,69,45,55,36,55,-20,-4,-31,-40,-15,-41,-12,-20,0,-23,3,-31,2,-31,-1,-47,5,-39,11,-27,11,-20,9,-19,16,-29,21,-33,19,-39,29,-35,33,-37,36,-29,40,-25,38,-23,41,-23,46,-17,44,-12,47,-5,45,-7,52,-35,68,-33,69,-14,61,9,45,5,43,16,32,14,43,29,38,30,34,34,33,45,38,58,40,59,40,60,41,71,48,79,59,81,57,87,67,90,66" shape="poly" href="/" alt="United States">

This is the div that would be toggled to be show with the United States information. 这是将切换为与美国信息一起显示的div。

<table class="hidden" id="United States">
<tbody><tr valign="top">
<td>
<a href="/countries/united-states"><img width="64" height="64" alt=""     src="http://dev-wateraid.pantheonsite.io/sites/default/files/flags/United-States.png" typeof="foaf:Image"></a>
 </td>
 <td>
 <h3>United States</h3>
 The America team helps to coordinate and fund operations across our country programs, with Nicaragua a particular focus.
 </td>
 </tr>
 </tbody></table>

I keep looking for reasons most of the countries might work but others wouldn't -- spelling is consistent -- I don't believe there are any hidden characters. 我一直在寻找大多数国家/地区可以使用但其他国家/地区无法使用的原因-拼写是一致的-我不相信有任何隐藏的字符。

I've validated the code as much as I could, but I just can't see it. 我已经尽力验证了代码,但看不到它。

I believe the issue may be the space in the "id", for example 我认为问题可能是“ id”中的空格,例如

id="United States"

may actually be interpreted as 实际上可以解释为

id="United"

jQuery selector can't handle "#United States"... It pretty much ignores the "States". jQuery选择器无法处理“ #United States” ...它几乎忽略了“ States”。 So if you really need the ID to be "United States" you can use: 因此,如果您确实需要ID为“美国”,则可以使用:

$("[id='"+$this.attr('alt')+"']")

Or you can just change the 'alt' and 'id' to "UnitedStates". 或者,您可以将“ alt”和“ id”更改为“ UnitedStates”。

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

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