2014-08-27 120 views
-2

所以,我有我的网站内的验证码用鼠标悬停时改变颜色? JavaScript的

<script type="text/javascript"> 
    $(document).ready(function(){ 
     $(".service_body").hide(); 
     //toggle the componenet with class menu_body 
     $(".service_head").click(function(){ 
      $(this).next(".service_body").slideToggle(600); 
      var plusmin; 
      plusmin = $(this).children(".plusminus").text(); 

      if(plusmin == ' ▾ ') 
       $(this).children(".plusminus").text(' - '); 
      else 
       $(this).children(".plusminus").text(' ▾ '); 
     }); 
    }); 
</script> 

我只是希望它所以当有人悬停在▾(.plusminus)指针它改变颜色来表示它的一个链接,扩大信息。 我一直在乱搞一个小时左右,不知道该怎么办?任何帮助将是非常感激

+12

对于简单的悬停,最好使用CSS。 '.plusminus:hover {color:green; }' – Gil 2014-08-27 12:22:31

+0

你可以添加这个函数附带的HMTL代码吗? – LinkinTED 2014-08-27 12:23:17

+0

显示HTML代码也 – Manwal 2014-08-27 12:25:37

回答

2

最好是使用CSS来解决这个问题:

.plusminus {color: blue;} 
.plusminus:hover {color: red;} 

你对扩展的内容查询,您可以使用jQuery的醉意表现出一些很好的提示。

0

你可以使用jQuery来获得这个。

$(".plusminus").hover(
    function() { 
     $(this).addClass("greenClass"); 
    }, 
    function(){ 
     $(this).removeClass("greenClass"); 
    } 
    ); 
0

我会建议CSS这一点,这样的:

.plusminus:hover{ 
    color:orange; 
} 

但你也可以做到这一点使用Javascript,例如,如果你愿意改变颜色只在项目都有特定的字符:

$('.plusminus').mouseenter(function(){ 
    if($(this).text() == ' ▾ ') //Remove this line if you want to change the color for both characters. 
     $(this).css({color: 'orange'}); 
}).mouseleave(function(){ 
    $(this).removeAttr('style'); 
});