gpt4 book ai didi

javascript - jquery bbq 从 url 中删除哈希 b

转载 作者:行者123 更新时间:2023-11-30 08:58:46 25 4
gpt4 key购买 nike

我是 jquery bbq 的新手,到目前为止我已经了解了大部分设置,但我有一个小问题。这是设置。

右侧有主要导航链接的页面每个导航链接点击都会将页面的正文内容更改为其相应的数据(显示和隐藏 div)(使用 bbq)其中一个链接显示带有另一组链接的 div,单击这些链接时将在 url 中设置哈希 B

所以第一个链接点击domain.com/dir/#A=page1

第二个链接点击domain.com/dir/#A=page1&B=set1

如果我按下后退按钮,它会返回到之前的 A 哈希,但是 B 哈希仍保留在 url 中。

有没有办法在不在特定页面上时删除 B peram?

$(window).bind('hashchange', function(e) {
var state = $.bbq.getState('p');
var graphState = $.bbq.getState('n');

var base_title = '{/literal}{$smarty.const.SITE_TITLE}{literal} | Dashboard | ';
$('.profile-nav a').each(function() {
if (!state) {
$('.profile-nav a').each(function() {
$('#' + this.id).removeClass('live active');
document.title = base_title + 'Message Center';
});
$('#m').addClass('live active');
} else if (state == this.id) {
$('#' + this.id).addClass('live active');
document.title = base_title + $(this).text();
} else {
$('#' + this.id).removeClass('live active');
}
});

if (!state) {
$('.tab-content').fadeOut('fast');
$('.message-content').fadeIn('slow');
} else {
$('.tab-content').fadeOut('fast');
clicked = $('#' + state).attr('rel').split(' ')[0];
$('.' + clicked).fadeIn('slow');
}

if (state == 'r') {
if (graphState) {
$('.nick-breakdown').fadeOut('fast');
$('#' + graphState).fadeIn('slow');
document.title = base_title + 'Reports | ' + $('#' + graphState).attr('rel');
} else {
$('.item-breakdown').fadeOut('fast');
$('.nick-breakdown').fadeIn('slow');
document.title = base_title + 'Reports';
}
}
});​

最佳答案

我使用带有 merge_mode = 2 的 jsbbq.pushState 完成了同样的事情,而不是仅仅在 anchor 上设置 #。

在此处查看文档:http://benalman.com/code/projects/jquery-bbq/docs/files/jquery-ba-bbq-js.html#jQuery.bbq.pushState

merge_mode(Number) : Merge behavior defaults to 0 if merge_mode is not specified (unless a hash string beginning with # is specified, in which case merge behavior defaults to 2), and is as-follows:

  • 0: params in the params argument will override any params in the current state.
  • 1: any params in the current state will override params in the params argument.
  • 2: params argument will completely replace current state.

因此,如果您的链接如下所示:

mysite.com#A=page1&B=page2 你可以调用

$.bbq.pushState({'A' : 'pageXYZ'}, 2);

然后您的文档位置将是:

mysite.com#A=pageXYZ

关于javascript - jquery bbq 从 url 中删除哈希 b,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11168342/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com