jquery点击函数select&取消选择

jquery click function select & deselect

本文关键字:amp 取消 选择 select 函数 jquery      更新时间:2023-09-26

我需要一些关于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>

最强调的方法是使用:http://api.jquery.com/toggle-event/

您可能在选择时添加一些类,然后在取消选择时删除该类

<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>