如何使用Javascript / jQuery解决Game Logic中的错误

问题描述 投票:2回答:1

This site takes you to my game, which will show the bug when you click on a few of the divs with points on them.

我正在制作类似危险的游戏。当用户单击其中一个子类别时,问题会成功弹出。用户也能够成功回答问题或成功回答问题;但是,在他们回答问题之后,逻辑似乎正在提升过去的点击次数,从而导致事件处理程序为新点击的目标和过去点击的目标执行功能。请参阅上面的链接,例如bug。

请帮我调试一下!

 let showQuestion = function(id){
        $('body > #simpleModal').css('display', 'block')
        $('.modal-body > .question').text(answerQuestion[id].answer)
    }
    let clickCounter = 0
    $('.container > .questionBox').on('click', this,  function() {
        clickCounter += 1
        let id = this.id
        showQuestion(id)
        let questionAnswered = this
        $('.modal-content > button').on('click', this, function(){
            $('body > #simpleModal').css('display', 'none')
            if ($('.modal-content > input').val() === answerQuestion[id].question){
                goodJob()
                $(questionAnswered).css('background-color', 'green') 
                $(questionAnswered).off()
            } else {
                tryAgain()
                $(questionAnswered).css('background-color', 'red') 
                $(questionAnswered).off()
            }

过去两周我一直参加网络发展课程,所以我还在学习。我的网站正在进行中。

javascript jquery debugging
1个回答
0
投票

看起来你在点击监听器中有一个点击监听器。有没有理由这样做?我想知道第一个,$('.container > .questionBox'),是否也在模态内部获得点击。但是,如果没有查看更多代码,我无法分辨,如果这就是为什么点击似乎在堆积起来。

© www.soinside.com 2019 - 2024. All rights reserved.