【问题标题】:Run another script after reloading the page with jquery使用 jquery 重新加载页面后运行另一个脚本
【发布时间】:2021-12-02 00:31:07
【问题描述】:

我有一个需要在使用 Jquery 重新加载页面后加载的要求。下面是代码。

$("a[id='gobutton']").click(function(e)) { 
  location.reload();
  somefunc(); 
});
function somefunc() { 
  alert("run my script"); }

【问题讨论】:

标签: javascript jquery


【解决方案1】:

运行 location.reload() 后,您的代码就消失了。你不能在它之后运行任何东西。 您需要将参数传递给页面才能运行该函数。

let param = new URLSearchParams(location.search);
$("a[id='gobutton']").click(function(e)) { 
  location.href = '?somefunc=true' 
});

if(param.get('somefunc'){
  somefunc()
}
function somefunc(){}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-02-22
    • 2016-11-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多