1

我在这段代码中使用烧烤历史插件:

$(window).bind( 'hashchange', function(e) {

    var url = $.param.fragment();           
    var new_page = url.replace('.php', '');

    if (new_page == 'product') {
        var new_page_num = 1;
    } else if (new_page == 'installations') {
        var new_page_num = 2;
    } else if (new_page == 'blog') {
        var new_page_num = 3;
    } else if (new_page == 'contact') {
        var new_page_num = 4;
    }

    if (new_page_num == cur_page_num) {
        return false;
    } else if (new_page_num > cur_page_num) {
        nextPage();
    } else if (new_page_num < cur_page_num) {
        previousPage();
    }

    // Remove class 'current'
    $('a.current').removeClass( 'current' );

    // Add .current class to "current" nav link(s), only if url isn't empty.
    url && $( 'a[href="#' + url + '"]' ).addClass( 'current' );

});

$(window).trigger( 'hashchange' );

在 'hashchange' 事件上,我想执行此操作:

比较当前 url (cur_page_num) 和下一个 url (new_page_num) 并执行 nextPage() 或 previousPage() 函数。

我可以获得下一个 url (var new_page)。

有谁知道我怎样才能得到我来自的哈希?

(localhost/#hash1 到 localhost/#hash2: hash1 < hash2 所以执行 nextPage();,我怎样才能得到 hash1?)

谢谢!!

4

0 回答 0