Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/477.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在JavaScript或Jquery中,使循环等待直到按下按钮才能继续_Javascript_Jquery_Html - Fatal编程技术网

在JavaScript或Jquery中,使循环等待直到按下按钮才能继续

在JavaScript或Jquery中,使循环等待直到按下按钮才能继续,javascript,jquery,html,Javascript,Jquery,Html,我正在创建一个HTML5应用程序,下面是我想做的: 我想创建一个循环,只要x小于y,它就会暂停,要求用户输入,一旦用户输入了什么,它就会检查x是否小于y,暂停并要求用户输入……直到x不再小于y 我希望输入是Framework7操作表中的按钮:因此我希望循环等待,直到用户按下其中一个按钮 这可以在Jquery或JavaScript中实现吗 ----额外信息----- 程序运行时,用户输入单词(我们称之为w),一旦他/她这样做并单击按钮。在此之后,输入被分成一个数组,其中每个字都是不同的值(称为数组

我正在创建一个HTML5应用程序,下面是我想做的:

我想创建一个循环,只要x小于y,它就会暂停,要求用户输入,一旦用户输入了什么,它就会检查x是否小于y,暂停并要求用户输入……直到x不再小于y

我希望输入是Framework7操作表中的按钮:因此我希望循环等待,直到用户按下其中一个按钮

这可以在Jquery或JavaScript中实现吗

----额外信息-----

程序运行时,用户输入单词(我们称之为w),一旦他/她这样做并单击按钮。在此之后,输入被分成一个数组,其中每个字都是不同的值(称为数组字)。我有一个数组来存储单词以及它们是什么词类。用户将确定他们的词性

我希望触发一个循环或事件(两者),如下所示:

for(i=0;i<words.length){
var buttons = [
    {
        text: 'What is "'+listandtypes[0][i]+'"', //word
        label: true
    },
    {
        text: 'Adjective',
        onClick: function () {
            listandtypes[1][i] = "adj"; //part of speech
            myApp.alert('Button1 clicked');
        }
    },
    {
        text: 'Adverb',
        onClick: function () {
            listandtypes[1][i] = "adv";
            myApp.alert('Button2 clicked');
        }
    },
    {
        text: 'Noun',
        onClick: function () {
            listandtypes[1][i] = "noun";
            myApp.alert('Button2 clicked');
        }
    },
    {
        text: 'Verb',
        onClick: function () {
            listandtypes[1][i] = "verb";
            myApp.alert('Button2 clicked');
        }
    },
    {
        text: 'Other',
        color: 'red',
        onClick: function () {
            listandtypes[1][i] = "idk";
            myApp.alert('Cancel clicked');
        }
    },
];
myApp.actions(buttons);
        } //I want this loop to wait until a button is pressed
//More code
}

for(i=0;i好的,所以我想出了方法(特别感谢@Bergi推荐):

函数selectWords(){
变量按钮=[
{
text:“什么是“+”列表和类型[0][the currentNum]+”,
标签:正确
},
{
文本:'形容词',
onClick:function(){
列表和类型[1][thecurrentnum]=“adj”;
currentnum=currentnum+1;
if(当前数量<字长){
选择单词();
}
否则{
定时器1();
}
log(“当前数:+thecurrentnum+”,长度:+thecurrentnum);
}
},
{
课文:'副词',
onClick:function(){
列表和类型[1][thecurrentnum]=“adv”;
currentnum=currentnum+1;
if(当前数量<字长){
选择单词();
}
否则{
定时器1();
}
}
},
{
文本:'名词',
onClick:function(){
列表和类型[1][thecurrentnum]=“名词”;
currentnum=currentnum+1;
if(当前数量<字长){
//currentnum=currentnum+1;
选择单词();
}
否则{
定时器1();
}
}
},
{
文本:'动词',
onClick:function(){
列表和类型[1][thecurrentnum]=“动词”;
currentnum=currentnum+1;
if(当前数量<字长){
//currentnum=currentnum+1;
选择单词();
}
否则{
定时器1();
}
}
},
{
正文:“其他”,
颜色:“红色”,
onClick:function(){
列表和类型[1][thecurrentnum]=“idk”;
currentnum=currentnum+1;
if(当前数量<字长){
//currentnum=currentnum+1;
选择单词();
}
否则{
定时器1();
}
}
},
];
myApp.actions(按钮);
}

不可以,因为按钮按下是异步的。请将函数重写为递归函数,然后从按钮的单击处理程序调用下一个“迭代”。
function selectWords(){

        var buttons = [
        {
            text: 'What is "'+listandtypes[0][thecurrentnum]+'"',
            label: true
        },
        {
            text: 'Adjective',
            onClick: function () {
                listandtypes[1][thecurrentnum] = "adj";
                thecurrentnum = thecurrentnum + 1;
                if(thecurrentnum < word.length){
                    selectWords();
                }
                else{
                    timer1();
                }
                console.log("Current Num: " +thecurrentnum+ ", Length: " +thecurrentnum);
            }
        },
        {
            text: 'Adverb',
            onClick: function () {
                listandtypes[1][thecurrentnum] = "adv";
                thecurrentnum = thecurrentnum + 1;
                if(thecurrentnum < word.length){
                    selectWords();
                }
                else{
                    timer1();
                }
            }
        },
        {
            text: 'Noun',
            onClick: function () {
                listandtypes[1][thecurrentnum] = "noun";
                thecurrentnum = thecurrentnum + 1;
                if(thecurrentnum < word.length){
                    //thecurrentnum = thecurrentnum + 1;
                    selectWords();
                }
                else{
                    timer1();
                }
            }
        },
        {
            text: 'Verb',
            onClick: function () {
                listandtypes[1][thecurrentnum] = "verb";
                thecurrentnum = thecurrentnum + 1;
                if(thecurrentnum < word.length){
                    //thecurrentnum = thecurrentnum + 1;
                    selectWords();
                }
                else{
                    timer1();
                }
            }
        },
        {
            text: 'Other',
            color: 'red',
            onClick: function () {
                listandtypes[1][thecurrentnum] = "idk";
                thecurrentnum = thecurrentnum + 1;
                if(thecurrentnum < word.length){
                    //thecurrentnum = thecurrentnum + 1;
                    selectWords();
                }
                else{
                    timer1();
                }
            }
        },
    ];
    myApp.actions(buttons);
}