我需要一些关于这个jQuery代码的帮助。我有一个SVG地图,我需要一个选择一个国家,只需点击一下,然后用另一个取消选择。有人能帮助我吗? :) 这是代码:
<script type="text/javascript">//<![CDATA[
$(window).load(function(){
$(document).ready(function() {
$("path").mouseover(function() {
$(this).css('cursor', 'pointer');$(this).attr({
fill: "#FF0000",
stroke: "#00FF00"
});
$(this).css('cursor', 'pointer');
})
.mouseout(function(){
if(!$(this).data('clicked')){
$(this).attr({
fill: "#FFFFFF",
stroke: "#eee"
});
}
});
$("path").click(function() {
$(this).attr({
fill: "#FF0000",
stroke: "#00FF00"
});
$(this).data('clicked', true);
});
});
});//]]>
</script>
答案 0 :(得分:2)
最重要的方法是使用:http://api.jquery.com/toggle-event/
答案 1 :(得分:0)
您可能在选择时添加了一些类,然后在取消选择时删除该类
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<input type='text' id="text1" onclick='javascript:toggleClass(this)' />
</body>
</html>
<script src="jquery-1.2.6.min.js" type="text/javascript"></script>
<script language='javascript' type="text/javascript">
function toggleClass(item) {
if ($(item).hasClass('select')) {
$(item).removeClass('select').addClass('deselect');
}
else {
$(item).removeClass('deselect').addClass('select');
}
}
</script>