简体   繁体   English

使“下一个”按钮起作用

[英]Making “next” button work

I am creating a simple numeracy game where by there is a grid populated with numbers. 我正在创建一个简单的数字游戏,其中有一个用数字填充的网格。 The numbers are hidden and when the game is run the grid space is highlighted. 数字被隐藏,并且在运行游戏时突出显示了网格空间。 A div on the side produces a sum to help the user get the correct answer. 一侧的div产生一个和,以帮助用户获得正确的答案。 The user then clicks the corresponding numbers that animate into position and signal whether they are right or wrong. 然后,用户单击动画到位置的相应数字,并发出信号指示对与错。

I have but in a next button ('.minibutton'), so that if the user gets the answer wrong 3 times they have a chance to move to the next question. 我只有一个下一个按钮('.minibutton'),因此,如果用户输入的答案错误3次,则他们就有机会移至下一个问题。 The button also has a .trigger('click') function so that when a word is completed correctly it moves on automatically and keeps the game flowing. 该按钮还具有.trigger('click')函数,以便在正确完成单词操作后会自动继续并保持游戏顺畅。

My problem is the button has stopped working and I am clueless as to why . 我的问题是按钮已停止工作,我对原因一无所知 Here is the ".minibutton" function... 这是“ .minibutton”功能...

$('.minibutton').click(function() {
var sum = $('#answerlist li[data-answer="' + answer + '"]').data('sum');
$(right).val('');
$(wrong).val('');
$('td').removeClass('spellanswer');
score.wrong = 0;
var r = rndanswer;
while (r == rndanswer) {
    rndanswer = Math.floor(Math.random() * (listOfanswers.length));
}

when I added this statement the button stopped working 当我添加此语句时,按钮停止工作

 //for (var x = 0; x < listOfanswers.length; x++) {
    //if (eval(sum.replace("=", "").replace("x", "*")) == listOfanswers[x].name) {
       // rndanswer = x;
   // }
//}

$('td[data-answer="' + listOfanswers[rndanswer].name + '"]').addClass('spellanswer');
$('td[data-answer=' + answer + ']').removeClass('answerglow').removeClass('answerglow4').removeClass('answerglow3').css('color', 'transparent');

var noExist = $('td[data-answer=' + listOfanswers[rndanswer].name + ']').hasClass('answerglow2');
if (noExist) {
    $('.minibutton').prop('disabled', false);

} else {

    $('.sumstyle').text(sum);
    sum.hide();

}
}).trigger("click");

http://jsfiddle.net/ZAfVZ/28/ http://jsfiddle.net/ZAfVZ/28/

Running the jsFiddle gives this error: 运行jsFiddle会出现此错误:

Object 1 + 2 = has no method 'hide'

You're trying to hide a string, which is obviously wrong. 您正在尝试隐藏字符串,这显然是错误的。 It's causing the script to stop executing after that point. 在那之后导致脚本停止执行。 Remove/comment out sum.hide() , and the 'next' button appears after three wrong guesses. 删除/注释sum.hide() ,然后在三个错误的猜测之后出现“下一步”按钮。

I've edited the JSFiddle to define sum (a text string containing the sum that the player is trying to answer) and seumElem (the HTML element containing the sum) at the top of the function: http://jsfiddle.net/ZAfVZ/30/ 我已经编辑了JSFiddle以在函数顶部定义sum (一个文本字符串,其中包含玩家尝试回答的总和)和seumElem (包含该总和的HTML元素): http : //jsfiddle.net/ZAfVZ / 30 /

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM