我正在使用 jquery,当鼠标悬停在具有 data-code=GB 属性的元素上时,如何触发警报?
我试过这个没有运气...
$(".jvectormap-container path[data-code='GB']").mouseover(function(){
alert('test');
});
谢谢
我正在使用 jquery,当鼠标悬停在具有 data-code=GB 属性的元素上时,如何触发警报?
我试过这个没有运气...
$(".jvectormap-container path[data-code='GB']").mouseover(function(){
alert('test');
});
谢谢
稍作修改,它对我有用。我补充说——
<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>
工作副本在这里:http: //jsbin.com/uwatiz/5/edit
为什么不使用 jVectorMap 的标准参数onRegionOver
?您的代码在 IE 中不起作用,因为 IE 中没有path
元素,而是使用它shape
。
你有一个div内的路径。这是错误的。通过正确使用路径,您的 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>
试试这个
$(function() {
$(".jvectormap-container").filter("path[data-code='GB']").on('mouseover',function(){
alert('test');
});
});