2011-11-13 107 views
0

嗨,我有點麻煩,我的jQuery選項卡,由於某種原因它加載第一個標籤的內容,但是當我選擇另一個選項卡的內容不顯示。當我嘗試回到第一個選項卡它也不加載。內容不加載在標籤

下面是HTML

JavaScript/DHTML/AJAX Syntax (Toggle Plain Text) 
<div id="content"> 
<div id="tabsX"> 
    <div id="tabContent"> 
    <ul class="tabs"> 
    <li><a id="all" href="#all" class="all">All</a></li> 
    <li><a id="free" href="#free" class="free">Free</a></li> 
    <li><a id="paid" href="#paid" class="paid">Paid</a></li> 
    <li><a id="completed" href="#completed" class="completed">Completed</a></li> 

    <div id="filter"><select name="filterQuest"> 
     <option>Name</option> 
     <option>Payout</option> 
     <option>Difficulty</option> 
    </select></div> 
    </ul> 


<div class="tab_container"> 
    <div id="all" class="tab_content"> 
     asddd 
    </div> 
    <div id="free" class="tab_content"> 
     <!--Content-->adadada 
    </div> 
    <div id="paid" class="tab_content"> 
     <!--Content-->adad 
    </div> 
    <div id="completed" class="tab_content"> 
     <!--Content-->adsasd 
    </div> 

</div><!--- end tab_container---> 
    </div><!---end tab content---> 
    <br class="clear" /> 
</div><!--- end tabsX---> 
<div id="tournament"></div><!--- end tournament---> 
</div><!--- end content---> 

這裏是JavaScript

JavaScript/DHTML/AJAX Syntax (Toggle Plain Text) 
<script type="text/javascript" 
src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script> 
<script type="text/javascript"> 

$(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(); //Fade in the active content 
     return false; 
    }); 

}); 
</script> 

這裏是CSS

JavaScript/DHTML/AJAX Syntax (Toggle Plain Text) 
@charset "utf-8"; 
/* CSS Document */ 

ul.tabs { 
    padding: 0; 
    float: left; 
    list-style: none; 
    height: 56px; 
    width: 100%; 
    margin-top: 0; 
    margin-right: 0; 
    margin-bottom: 0; 
    margin-left: 0; 
    border-bottom-width: 1px; 
    border-bottom-style: ridge; 
    border-bottom-color: #999; 
    position:relative; 


} 
#tabsX { 
    width: 800px; 
    padding-left: 20px; 
    float: left; 
} 
#tabsX .clear { 
    clear: both; 
} 



ul.tabs li { 
    float: left; 
    padding: 0; 
    height: 55px; 
    line-height: 53px; 
    margin-bottom: -1px; 
    overflow: hidden; 
    position: relative; 
    margin-top: 0px; 
    margin-right: 20px; 
    margin-left: 0; 
    font-family: Georgia, "Times New Roman", Times, serif; 
    font-size: 12px; 


} 
ul.tabs li a { 
    text-decoration: none; 
    color: #333; 
    display: block; 
    font-size: 1.2em; 
    padding: 0 20px; 
    outline: none; 
    position:relative; 

} 
/*ul.tabs li a:hover { 
    color: #9C3; 
    text-transform: none; 
}*/ 
html ul.tabs li.active a.all, 
ul.tabs li a.all:hover { 
    color: #999; 
    text-transform: none; 
    border-bottom-width: thick; 
    border-bottom-style: ridge; 
    border-bottom-color: #999; 
} 
html ul.tabs li.active a.free, 
ul.tabs li a.free:hover { 
    color: #7ED200; 
    text-transform: none; 
    border-bottom-width: thick; 
    border-bottom-style: ridge; 
    border-bottom-color: #7ED200; 
} 
html ul.tabs li.active a.paid, 
ul.tabs li a.paid:hover { 
    color: #CB0C01; 
    text-transform: none; 
    border-bottom-width: thick; 
    border-bottom-style: ridge; 
    border-bottom-color: #E40D01; 
} 
html ul.tabs li.active a.completed,  
ul.tabs li a.completed:hover { 
    color: #06C; 
    text-transform: none; 
    border-bottom-width: thick; 
    border-bottom-style: ridge; 
    border-bottom-color: #06C; 
} 

.tab_container { 
    clear: both; 
    /*float: left;*/ 
    width: 100%; 
    border-right: 1px ridge #999; 
    margin-bottom: 20px; 
    min-height: 930px; 

} 
.tab_content { 
    padding: 20px; 
} 

.tab_content img { 
    float: left; 
    margin: 0 20px 20px 0; 
    border: 1px solid #ddd; 
    padding: 5px; 
} 
#tabContent #filter { 
    float: right; 
    margin-top: 17px; 
    margin-right: 50px; 
} 
+0

您的控制檯中是否收到任何js錯誤? – dSquared

回答

1

首先,HTML ID屬性必須是唯一的。在你的例子中,幾個元素具有相同的ID,這是錯誤的(對於XHTML驗證和JS-這導致錯誤)。

其次,您是否使用過調試器來查看單擊鏈接時$(this)包含的內容?

最後,「類轉換」的東西是否工作?我們需要您提供更多信息:-)

+0

也不應將div放在無序列表中。 – dSquared

+0

呃的確沒有看到。 –

+0

感謝您的回覆,我試圖調試代碼來查找$(this)的值,​​但我遇到了麻煩,我試圖在Internet Explorer中,但它似乎並沒有工作,你能給我一些建議,我可以調試它來查找$(this)的值。謝謝 –