事件委托可以使这变得容易。
google.load("jquery", "1.6.2");
google.setOnLoadCallback(function(){
$(".horzNavigation").delegate("ul > li > a:not(.active)",{
"mouseenter": function(){
$(this).stop(true,true).animate({"top": "-=60px"}, 250, 'swing');
},
"mouseleave": function(){
$(this).stop(true,true).animate({"top": "+=60px"}, 250, 'swing');
}
}).delegate("ul > li > a","click",function(event){
$(this).addClass('active').parent().siblings().children('.active').removeClass('active');
});
});
另外,我假设您的代码中有错字,ul元素不能直接包含锚标签,所以我在li标签中添加了选择器。无效的 html 在不同的浏览器中可能会产生不一致的结果。