2014-01-21 5 views
0

Имея несколько проблем с кодом.Удалить hashtag с url

$(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

ВАША ЗВЕЗДА! Я УДАЛ, ЧТО ЕЖЕГОДНО СЛИШКОМ: / –

0

Вы должны переместить event.preventDefault() в обработчик щелчка, который получает событие.

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

    // rest of the handler code goes here... 
} 
Смежные вопросы