繁体   English   中英

使用JQuery检索浏览器状态信息

[英]Retrieving browser state information with JQuery

我使用状态来记住用户单击了哪些链接。 当前,我只想提醒状态信息,但是此代码无法正常工作:

function onLinhaClick(obj) {
    $("#linha").children("a").off("click");
    history.pushState({ item : $(obj).attr("data-value") }, $(obj).children("span").html(), $(obj).attr("href"));
    $(obj).nextAll().remove();
    $("#linha").children("a").on("click", function(e) {
        e.preventDefault();
        onLinhaClick($(this));
    });
}

function onMateriaClick(obj) {
    $("#materias").children("a").off("click");
    history.pushState({ value : $(obj).attr("data-value") }, $(obj).children("span").html(), $(obj).attr("href"));
            /*some not important code*/
}

$(document).ready(function() {
    $("#linha").children("a").on("click", function(e) {
        e.preventDefault();
        onLinhaClick($(this));
    });
    $("#materias").children("a").on("click", function(e) {
        e.preventDefault();
        onMateriaClick($(this));
    });
});

$(window).on("popstate", function(e) {
    alert(JSON.stringify(e.state));
});

该警报仅显示“未定义”,并且我遵循了一些文档,但没有帮助。

尝试改变

$(window).on("popstate", function(e) {
    alert(JSON.stringify(e.state));
});

window.onpopstate = function(e) {
    alert(JSON.stringify(e.state));
}

正如这个问题中提到的

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM