Jquery 从url中删除hashtag
代码有一些问题Jquery 从url中删除hashtag,jquery,web,hashtag,Jquery,Web,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).addClas
$(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
我想删除#tab1、#tab2、#tab3、#tab4等等第四个
有什么想法吗?我已经尝试了所有内容…如果您不想使用hashtags,您可以轻松删除这一行:
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();
您需要在接收事件的单击处理程序中移动
事件.preventDefault()
$(this).click(function (event) {
event.preventDefault();
// rest of the handler code goes here...
}
你是个明星!我之前也删除了:/