function loadThisUrl(yr){
    if ('URLSearchParams' in window) {
        var searchParams = new URLSearchParams(window.location.search);
        searchParams.set("get_of_year", yr);

        window.location.search = searchParams.toString();
        //window.location.hash="yeartabwrapper";
    }
}


此代码生成如下网址:

http://localhost/gipfipan/pedagogical-action/update?id=5&get_of_year=2017


我想像下面的URL:

http://localhost/gipfipan/pedagogical-action/update?id=5&get_of_year=2017/#yeartabwrapper

最佳答案

如果您确实在搜索之前分配了哈希,它将起作用

function loadThisUrl(yr){
    if ('URLSearchParams' in window) {
        var searchParams = new URLSearchParams(window.location.search);
        searchParams.set("get_of_year", yr);
        window.location.hash="yeartabwrapper";
        window.location.search = searchParams.toString();
    }
}

关于javascript - 如何在URL jquery中添加一些参数和hash(#)id?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48394878/

10-11 13:01