从网址中删除主题标签 [英] Remove hashtag from url

查看:129
本文介绍了从网址中删除主题标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码有一些问题.

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

});

,这是网址 http://www.r1hosting.net/vps-servers#tab1

我要删除#tab1,#tab2,#tab3,#tab4等第四个...

I want to remove the #tab1, #tab2, #tab3, #tab4 and so fourth...

有什么想法吗?我已经尝试过一切...

Any ideas? I've tried next to everything...

推荐答案

您需要在接收事件的点击处理程序中移动event.preventDefault().

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...
}

这篇关于从网址中删除主题标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆