Javascript 是否有一个for循环等待直到间隔被清除
我有一个for循环在节点列表中运行。我正在尝试运行节点列表并触发单击,然后设置等待弹出窗口的间隔,然后在弹出窗口中触发单击 我的问题是,我需要每次迭代都要等到弹出窗口被加载并且弹出窗口中的项目被单击后,才能进入下一次迭代。希望这是有意义的 这是我的密码Javascript 是否有一个for循环等待直到间隔被清除,javascript,html,node.js,for-loop,intervals,Javascript,Html,Node.js,For Loop,Intervals,我有一个for循环在节点列表中运行。我正在尝试运行节点列表并触发单击,然后设置等待弹出窗口的间隔,然后在弹出窗口中触发单击 我的问题是,我需要每次迭代都要等到弹出窗口被加载并且弹出窗口中的项目被单击后,才能进入下一次迭代。希望这是有意义的 这是我的密码 let checkSteats = () => { const seats = document.querySelectorAll(seatSectionSelector); if (seats.length < maxSea
let checkSteats = () => {
const seats = document.querySelectorAll(seatSectionSelector);
if (seats.length < maxSeatCount) {
maxSeatCount = seats.length;
}
if (seats.length > 0) {
[].forEach.call(seats, (seat, index) => {
/**
* WE NEED TO CLICK WAIT FOR A CHANGE IN THE RESPONSE OR POP UP BEFORE WE GO INTO THE NEXT ITERATION
*/
console.log(seat)
if ((index+1) <= maxSeatCount) {
seat.dispatchEvent(
new MouseEvent('click', {
view: window,
bubbles: true,
cancelable: true,
buttons: 1
})
);
const popupInterval = setInterval(() => {
const popupBtn = document.querySelector('.ticket-option__btn');
if (popupBtn) {
popupBtn.click();
clearInterval(popupInterval);
}
}, 100)
}
});
}
};
让checkSteats=()=>{
const seats=document.queryselectoral(seatSectionSelector);
if(座位长度<最大座位数){
maxSeatCount=座椅长度;
}
如果(座椅长度>0){
[]forEach.call(座位,(座位,索引)=>{
/**
*在进入下一个迭代之前,我们需要单击等待响应中的更改或弹出窗口
*/
控制台日志(座椅)
如果((索引+1){
const popubtn=document.querySelector('.ticket-option__btn');
if(popuptn){
popubtn.click();
clearInterval(popupInterval);
}
}, 100)
}
});
}
};
您想使用一个基本队列,在该队列中,您可以使用shift()从数组的前面提取项目
var myArray=[1,2,3,4]
函数nextItem(){
var item=myArray.shift();
setTimeout(函数(){
控制台日志(项目);
if(myArray.length)nextItem();
}, 1000)
}
nextItem()
您不应该为此使用循环。应该是一个从数组中转移()项的方法。不是100%的关于如何将它合并到我的代码中。得到了它的工作伙伴-非常感谢你,你是一个完整的救命恩人!我欠你一个人情!!!