0

I have this jQuery Tab Code:

$(function() {  
  $('#tabs div').hide(); // Hide divs
  $('#tabs div:first').show(); // Show first div
  $("li").click(function(e) {
    e.preventDefault();
    $("li").removeClass("selected");
    $(this).addClass("selected");
    var currentTab = $(this.children).attr('href'); // Set currentTab to value of href attribute
    $('#tabs div').hide(); // Hide all divs
    $(currentTab).show(); // Show div with id equal to variable currentTab
    return false;
  });
});

The thing is, that each time I click on an anchor links it "toggles" a tab:

<div id="tabs">
<ul class="tabrow">
  <li class="selected"><a href="#tab-one">Contest</a></li>
<li><a href="#tab-two">Prizes</a></li>


</ul>

<div id="tab-one" class="center">
</div>
<div id="tab-two" class="center">
</div>
</div>

How can I do so only the links in the UL will be affected by this jQuery code?

4

3 回答 3

0

尝试改变

$("li").click(

$(".tabrow a").click(
于 2013-10-13T19:02:53.220 回答
0
$('ul.tabrow li a').click(function(e) {
    var $li = $(this).parent();
    $li.removeClass('selected');
    // etc...
});

您的 jQuery 选择器不够具体。您需要为点击事件定位锚标记,或使用.delegate代替.click( .bind)。

于 2013-10-13T19:03:01.907 回答
0

试试这个... $('a.something').on("click", function (e) { e.preventDefault(); }); });

它将禁用锚标签。

于 2013-10-13T19:20:59.763 回答