目前我有一個非常簡單的選項卡系統設置,問題是當你點擊標籤的頁面向上移動,但不是所有的方式到頂部。我試過返回false;和e.preventDefault();在我的點擊事件。這些似乎都沒有工作。如果任何人可以幫助我停止頁面移動時,單擊一個標籤,這將是偉大的。這裏是我的代碼,也知道我只有e.preventDefault();在我的單擊事件,但我也試圖返回假太:jquery選項卡哈希標記問題
$(".tab_content").hide();
$(".bat-tabs li:first").addClass("active").show();
$(".tab_content:first").show();
$("#nav-container").css("border-top", "3px solid #F79C0C");
$(".bat-tabs li > a").click(function (e) {
$(".bat-tabs li").removeClass("active");
$(this).parent().addClass("active");
$(".tab_content").hide();
var activeTab = $(this).attr("href");
$(activeTab).fadeIn();
e.preventDefault();
});
這是我真正的HTML
Thank you guys for both responding so quickly. For jbrookover: not sure how i should implement your solution bc right now for each one of my links i have a corresponding #+('tab name'), like this: { <div class="clearfix">
<ul class="bat-tabs clearfix">
<li><a href="#baseball" title="click to see all our choices for baseball bats" class="active"><h2>Baseball Bats</h2></a></li>
<li><a href="#fast" title="click to see all our choices for fastpitch bats"><h2>Fastpitch Bats</h2></a></li>
<li><a href="#slow" title="click to see all our choices for slowpitch bats"><h2>Slow Pitch Bats</h2></a></li>
</ul>
</div>
<div id="nav-container" class="section clearfix nav">
<div id="baseball" class="tab_content">
content here
</div>
<div id="fast" class="tab_content">
content here
</div>
<div id="slow" class="tab_content">
content here
</div>
</div> }
如果出現以下情況,您將在URL中看到#作爲最後一個參數:a)jquery腳本尚未加載。 b)腳本本身有問題。你有螢火蟲嗎? – arma 2011-04-07 18:37:44
對不起,要求愚蠢的問題,但仍然是非常新的jquery,是的,我有螢火蟲,但我通常只使用控制檯在鉻 – Lawrence 2011-04-07 18:45:07
也#那些#是不是在 – Lawrence 2011-04-07 18:45:36