2014-01-21 95 views
0

在代碼中遇到幾個問題。從網址中刪除hashtag

$(function() { 
    var items = $('#v-nav>ul>li').each(function() { 
     $(this).click(function() { 
      //remove previous class and add it to clicked tab 
      items.removeClass('current'); 
      $(this).addClass('current'); 

      //hide all content divs and show current one 
      $('#v-nav>div.tab-content').hide().eq(items.index($(this))).show('fast'); 

      window.location.hash = $(this).attr('tab'); 
     }); 
    }); 

    if (location.hash) { 
     showTab(location.hash); 
    } 
    else { 
     showTab("tab1"); 
    } 

    function showTab(tab) { 
     $("#v-nav ul li[tab=" + tab + "]").click(); 
    } 

    // stop the click on the link adding a # to the end of the 
    event.preventDefault(); 

    // Bind the event hashchange, using jquery-hashchange-plugin 
    $(window).hashchange(function() { 
     showTab(location.hash.replace("#", "")); 
    }) 

    // Trigger the event hashchange on page load, using jquery-hashchange-plugin 
    $(window).hashchange(); 

}); 

,這是url http://www.r1hosting.net/vps-servers#tab1

我想刪除#TAB1,TAB2#,#TAB3,#TAB4等第四...

任何想法?我試過旁邊一切......

回答

0

如果你不希望使用#標籤,你可以很容易地刪除此行:

window.location.hash = $(this).attr('tab'); 

如果刪除,該代碼不會做任何事情,因爲該#沒有設置,可以藏漢被刪除:

// Bind the event hashchange, using jquery-hashchange-plugin 
$(window).hashchange(function() { 
    showTab(location.hash.replace("#", "")); 
}) 

// Trigger the event hashchange on page load, using jquery-hashchange-plugin 
$(window).hashchange(); 
+0

YOUR A STAR!我刪除了這個太早:/ –

0

您需要接收事件的點擊處理程序中移動event.preventDefault()

$(this).click(function (event) { 
    event.preventDefault(); 

    // rest of the handler code goes here... 
}