问题
Having a few issues with the code.
$(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();
});
and this is the url http://www.r1hosting.net/vps-servers#tab1
I want to remove the #tab1, #tab2, #tab3, #tab4 and so fourth...
Any ideas? I've tried next to everything...
回答1:
If you don't want to use hashtags, you can easily remove this line:
window.location.hash = $(this).attr('tab');
If you remove that, this code would not do anything since the # is not set and can be removed aswell:
// 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();
回答2:
You need to move the event.preventDefault()
within a click handler that receives the event.
$(this).click(function (event) {
event.preventDefault();
// rest of the handler code goes here...
}
来源:https://stackoverflow.com/questions/21268075/remove-hashtag-from-url