2010-04-28 97 views
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瀏覽器?jQuery fadeIn()在IE中不工作

+0

而不是返回false你應該使用preventDefault() – Samuel 2010-04-28 22:13:39

+0

嗯。我不希望任何涉及alpha混合的東西在IE中正常工作,但也許這僅僅是因爲它支持PNG的程度有多嚴重...... – SamB 2010-04-28 22:15:15

回答

1

你可以做到這一點得到一致的行爲:

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

IE喜歡返回不"#id",而是它認爲你想:"http://site.com/currentPage.html#id",這將不是一個選擇工作:)我給你搶.hash關閉DOM元素,你只會得到他一致的部分。

You can find a bit more discussion on why this happens in this question

+0

啊,你是說它喜歡馬上解析相對URI? – SamB 2010-04-28 23:30:15

0

$(this).find("a").attr("href")讓你的目標,而不是目標的HREF。假設你將DIV的名稱放在href中,那可能是正確的(我不知道里面是什麼)。

嘗試alert($(this).find("a").href())以查看您是否擁有正確的元素,或只是嘗試.show()並查看會發生什麼情況。