且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在jquery中重新加载页面后运行代码

更新时间:2022-12-07 08:38:08

好吧。如果您重新加载页面,任何JavaScript都会被停止并重新加载。如果你希望你的代码在重新加载页面后运行,你可以添加一个哈希值。

Well. If you reload your page, any JavaScript is stopped and reloaded too. If you want your code to run AFTER the page is reloaded you could add a hash.

window.location.hash = "triggerReloadCode";
window.location.reload();

if (window.location.hash.substr(1) == "triggerReloadCode") {
    window.location.hash = "";
    /* Statements */
}

我不知道是不是***的做法,但我会像这样触发它。

I don't know if that's best practice, but I would trigger it like this.