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"セレクターでは機能しません:) .hashDOM要素を取得すると、#id一貫して彼の部分だけが取得されます。

この質問でこれが発生する理由についてもう少し議論を見つけることができます

于 2010-04-28T22:13:21.447 に答える
0

$(this).find("a").attr("href")ターゲットではなく、ターゲットのHREFを取得します。あなたがそこのhrefにDIVの名前を入れていると仮定すると、それは正しいかもしれません(私はそこに何が入っているのかわかりません)。

alert($(this).find("a").href())適切な要素があるか.show()どうかを確認するか、何が起こるかを確認してください。

于 2010-04-28T22:17:28.573 に答える