【问题标题】:Make a loop pause until a user inputs something, then continue, in Javascript or Jquery?在 Javascript 或 Jquery 中让循环暂停直到用户输入内容,然后继续?
【发布时间】:2014-11-04 05:49:46
【问题描述】:

我正在创建一个 HTML5 应用程序,这就是我想要做的:

我想创建一个循环,只要 x 小于 y,它就会暂停,询问用户输入,一旦用户输入内容,它会检查 x 是否小于 y,暂停并询问用户输入...直到 x 不再小于 y。

我希望输入是来自 Framework7 操作表的按钮:http://www.idangero.us/framework7/docs/action-sheet.html#.VFhLMBb4oUM 所以我希望循环等到用户按下其中一个按钮。

这可以在 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
}

【问题讨论】:

    标签: javascript jquery html loops


    【解决方案1】:

    这种类型的功能最好用事件而不是循环来处理。 在输入上创建一个事件。单击按钮,输入按下或跳出该字段。附加一个事件处理程序并检查那里的条件。

    【讨论】:

      猜你喜欢
      • 2017-08-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-13
      • 1970-01-01
      相关资源
      最近更新 更多