gpt4 book ai didi

页面更改后 Javascript 代码不执行

转载 作者:行者123 更新时间:2023-12-01 02:22:55 25 4
gpt4 key购买 nike

所以,我正在尝试运行这段代码

document.location = "https://stackoverflow.com/questions/ask";
document.onload = function(){document.getElementById("title").value="My question";};

但事实证明我的函数没有运行该函数。您可以通过执行以下操作来观察这一点

document.location = "https://stackoverflow.com/questions/ask";
document.onload = function(){document.getElementById("title").value="My question";alert('Hi');};

我的问题是,我做错了什么?为什么函数不运行?

最佳答案

有人问过类似的问题here !

以下引用了已接受且获得最多支持的答案中最重要的部分:

No, you cannot do it the way you want. Loading a new page closes the current document and starts loading a new document. Any code in your current document will no longer be active when the new page starts to load. - Source: Answer by jfriend00

关于页面更改后 Javascript 代码不执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49061162/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com