2011-08-10 52 views
-1

我想要爲標籤獲取簡單的jQuery顏色懸停效果。您可以在此jsFiddle中發現它無法正常工作。另外,我將如何獲得緩解的影響呢?謝謝。jQuery .hover效果'顏色'不能正常工作

$(document).ready(function() { 
var origColor = $("#links-top-contact").children('a').css("color"); 
    $("links-top-contact").children('a').hover(function() { 
     $(this).css('color' , 'blue'); 
      $("links-top-contact").children('a').hover(function() { 
       $(this).css(origColor); 
      }); 
     }); 
    }); 

回答

3
$(document).ready(function() { 
    var origColor = $("#links-top-contact a").css("color"); 
    $("#links-top-contact a").hover(function() { 
     $(this).css({color:'blue'}); 
    },function() { 
     $(this).css({color:origColor}); 
    }); 
}); 

更新小提琴 http://jsfiddle.net/uHYVf/

+0

真棒謝謝!只是好奇,什麼是額外括號和逗號爲:$(this).css({color:'blue'}); -------------------->},<------這裏。我一直看到這個語法,看起來不合適。 – Graham

+1

jQuery中的懸停事件可以使用2個函數。第一個是鼠標懸停,第二個是鼠標懸停。請參閱此處瞭解更多信息http://api.jquery.com/hover/ –