0
我的頁面有兩個「標籤」導航部分。兩者都相互獨立,但導致相同的結果。我想最簡單的方法是將它們編碼在一起工作,找到兩個部分中相同的'href'屬性,將其保存在一個變量中,然後從那裏繼續。jQuery找到類似的屬性
我的佈局看起來像這樣。
<div id="tab-text">
<a href="tab-1"></a>
<a href="tab-2"></a>
<a href="tab-3"></a>
</div>
<div id="tab-arrow">
<a href="tab-1"></a>
<a href="tab-2"></a>
<a href="tab-3"></a>
</div>
而我有一些這樣的jQuery。
jQuery('#tab-text a').click(function()
{
jQuery('#tab-text a').removeClass('active');
jQuery(this).addClass('active');
}
所以,我怎麼能包括jQuery的,如果#tab-text a
被點擊,比找到href
屬性的值,而不是從#tab-arrow a
搜索該值和.addClass()
請問'this.href 「工作?我相信它應該是'$(this).attr('href')'。 – unclenorton
@unclunorton - 不需要額外的jQuery對象。 'this.href'也可以工作(也許aven更好) – Neal
嗯我寫了基本相同的東西......'var active_tab = jQuery(this).attr('href');'很奇怪爲什麼它不工作.. 。 – cnotethegr8