jquery选择器作为自定义属性

jquery选择器作为自定义属性,jquery,Jquery,我正在使用jquery,当鼠标悬停在数据代码为GB atribute的元素上时,如何触发警报 我试过了,但运气不好 $(".jvectormap-container path[data-code='GB']").mouseover(function(){ alert('test'); }); 谢谢你你的路径在一个div中。这是错误的。正确使用path后,js代码可以正常工作 <svg xmlns="http://www.w3.org/2000/svg" version=

我正在使用jquery,当鼠标悬停在数据代码为GB atribute的元素上时,如何触发警报

我试过了,但运气不好

  $(".jvectormap-container path[data-code='GB']").mouseover(function(){
     alert('test');
  });

谢谢你

你的路径在一个div中。这是错误的。正确使用path后,js代码可以正常工作

<svg xmlns="http://www.w3.org/2000/svg" version="1.1" class="jvectormap-container">
 <path d="M150 0 L75 200 L225 200 Z" data-code='GB' />
</svg>

稍加修改,它对我有用。 我补充说:

<head>
 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
 <script>
   $(document).ready(function(){
     $('.jvectormap-container path[data-code="GB"]').bind('mouseover', function(){
       alert('test');
     });
   });
  </script>
</head>

$(文档).ready(函数(){
$('.jvectormap容器路径[data code=“GB”]').bind('mouseover',function(){
警报(“测试”);
});
});
工作副本在这里:

试试这个

$(function() {
    $(".jvectormap-container").filter("path[data-code='GB']").on('mouseover',function(){
        alert('test');
    });
});

为什么不使用jVectorMap
onRegionOver
的标准参数?你的代码在IE中不起作用,因为IE中没有
路径
元素,它使用
形状

代码在这里-元素的实际名称是
路径
?倒引号会有区别吗<代码>$('.jvectormap容器路径[data code=“GB”]”)我尝试反转引号,但没有成功:-(您甚至不需要在属性选择器中使用引号,因为属性值中没有特殊字符。我无法将svg从DIV中取出。但是我确实向svg元素添加了xlmns、version和类。但是仍然没有运气:-($('.jvectormap container svg:first').attr('xmlns',');$('.jvectormap container svg:first')).attr('version','1.1');$('.jvectormap容器svg:first').attr('class','jvectormap容器');