我正在寻找一种无需刷新页面即可使用 javascript(包括 jquery)更改 html 请求的查询字符串的方法。刷新时将保留此查询字符串。例如,http://thissite.site/index.html?id=123
是原来的 url,然后发生事件,id 变为 235。当页面刷新时,刷新的链接将是 http://thissite.site/index.html?id=235.
最佳答案
window.location.search = "?id=" + encodeURIComponent(new_value)
https://developer.mozilla.org/docs/DOM/window.location
https://developer.mozilla.org/docs/JavaScript/Reference/Global_Objects/encodeURIComponent
关于Javascript 更改查询字符串以进行刷新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12269367/