gpt4 book ai didi

javascript - 在浏览器控制台中执行时暂停 Javascript

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:57:07 24 4
gpt4 key购买 nike

我需要在 Chrome 的控制台中延迟执行 Javascript。如何做到这一点?

我需要这个的原因是,一旦焦点从网页(或网页的某个元素)发生变化,它就会被重新绘制。因此,我想延迟几秒启动我在控制台中执行的脚本,这样我就可以将焦点转移到我正在使用的页面上的正确元素。

编辑 1:Dinesh Padiyan。

对我不起作用,屏幕截图:

enter image description here

最佳答案

如果您出于调试目的需要延迟,则需要将 debugger; 语句添加到您的代码中。当您添加调试器并打开您的开发者工具时,脚本执行将在您的 debugger; 语句处暂停,您可以在开发者工具中检查您的代码。

console.log('I will execute');
debugger; // execution will pause at this line
console.log("I won't execute until you say so");

如果您需要延迟执行您的站点行为,您可以使用setTimeout() 来延迟调用。

console.log('I will be printed immediately');
setTimeout(function() {
console.log('I will be printed after 5s');
}, 5000); // 5s delay

关于javascript - 在浏览器控制台中执行时暂停 Javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53395496/

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