我通过从与某个类名匹配的元素数组中获取 href 属性来获取 URL 列表。直到这里一切都很顺利。然后,我尝试通过迭代 URL 数组,每 10 秒更改一次页面的 location.href。但出于某种原因,什么也没有发生。我做错了什么?
var buttonsElements = document.getElementsByClassName("elementor-button-link elementor-button");
console.log(buttonsElements.length);
for(i=0;i<buttonsElements.length;i++) {
console.log(buttonsElements[i].href);
//everything works just fine until here
setTimeout(function(){
window.location.href = buttonsElements[i].href;
},10000);
}
最佳答案
我不太清楚你想做什么。请注意,一旦您分配了 href,浏览器就会将您带到另一个页面,并且脚本将被中断。
关于Javascript:每 10 秒从 URL 数组中更改 location.href ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59824161/