0
$(document).ready(function() {

 //Default Action
 $(".tab_content").hide(); //Hide all content
 $("ul.tabs li:first").addClass("active").show(); //Activate first tab
 $(".tab_content:first").show(); //Show first tab content

 //On Click Event
 $("ul.tabs li").click(function() {
  $("ul.tabs li").removeClass("active"); //Remove any "active" class
  $(this).addClass("active"); //Add "active" class to selected tab
  $(".tab_content").hide(); //Hide all tab content
  var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
  $(activeTab).fadeIn("slow"); //Fade in the active content
  return false;
 });

});

适用于除 IE 之外的所有应用程序?

4

2 回答 2

1

您可以这样做以获得一致的行为:

var activeTab = $(this).find("a").get(0).hash;

IE 不喜欢返回"#id",而是认为你想要返回: "http://site.com/currentPage.html#id",这对选择器不起作用:) 如果你.hash从 DOM 元素中取出,你只会得到他#id一致的部分。

您可以在这个问题中找到更多关于为什么会发生这种情况的讨论

于 2010-04-28T22:13:21.447 回答
0

$(this).find("a").attr("href")为您提供目标的 HREF,而不是目标。假设您将 DIV 的名称放在其中的 href 中,这可能是正确的(我不知道那里有什么)。

试着alert($(this).find("a").href())看看你是否有正确的元素,或者只是试着.show()看看会发生什么。

于 2010-04-28T22:17:28.573 回答