我正在创建一个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
}
答案 0 :(得分:0)
好的,所以我想出了如何做到这一点(特别感谢@Bergi推荐这个):
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);
}