等待点击循环 [英] Wait for click in loop

查看:56
本文介绍了等待点击循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在开始之前,我知道已经有一个线程,但不幸的是,它根本没有帮助我.

Before even starting, I know there already has been a thread about this, but unfortunately it did not help me at all.

所以这是我的问题,我有一个用JavaScript编写的循环,它的最后是一个按钮单击事件.该事件与位于弹出窗口内的按钮有关.

So here is my problem, I have a loop written in JavaScript and at the end of it is a button click event. The event is related to a button situated inside a popup window.

for(var i=0; i<value; i++){
  [...]
  //some code here
  [...]
  //opens the window
  windowButton.addEventListener('click', function(){
    //code
  });
  //here I would like for it to continue once the click has been triggered
}

不幸的是,它不等待点击.

Unfortunately, it doesn't wait for the click.

就像在类似的帖子中所说的那样,在函数内部增加变量 i 不起作用,甚至不使用全局变量.而且建议的答案也不是我想要的.

Like said in the similar post, incrementing the variable i inside the function doesn't work, or even using a global variable. And the suggested answers are not what I am looking for.

好的,所以我将添加一些信息以更精确.我需要创建一个表格.但是它还需要能够解析包含所有信息的文件,并能够填充它.对于文件的每一行信息,因此每次填写表单时,都需要打开一个窗口并等待其中的验证按钮.

Okay, so I'm going to add some information to be more precise. I need to create a form. But it also needs to be able to parse a file containing all the information, and to be able to fill it. For each line of information of the file, so each time the form is completely filled, a window needs to open and wait for the validate button situated inside it.

我希望我能说得足够清楚.[/EDIT]

Si I am hoping I made myself clear enough. [/EDIT]

预先感谢您的回复

推荐答案

无法在JavaScript中暂停功能.您需要彻底改变您的方法.

There is no way to pause a function in JavaScript. You need to completely change your approach.

将每次循环运行的代码每次循环到一个单独的函数中.

Move the code that you currently run each time you go around the loop into a separate function.

在该函数之外创建一个变量.

Create a variable outside that function.

每次调用该函数时,都要递增该变量.

Each time the function is called, increment that variable.

如果变量太大",则在执行任何操作之前从函数返回.

If the variable is "too big" return from the function before doing anything.

将该功能分配为您的点击事件处理程序.

Assign that function as your click event handler.

这篇关于等待点击循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆