【问题标题】:Javascript & jquery return valueJavascript & jquery 返回值
【发布时间】:2015-04-13 04:29:42
【问题描述】:

我已经盯着下面的问题看了 3 个小时了。在完成代码底部的“newLevel”功能后,我想从头开始整个代码。我一直在尝试将代码包装在 if() 和 while() 语句中,但无法让它工作。

简而言之,问题是 newLevel() 函数不能将变量 level 的新值发送到代码的开头。我怎么能这样做?

感谢您的反对!

$(document).ready(function(){

var level = 1;

if(level == 1)
{random variables}

if(level == 2)
{random variables}

if(level == 3)
{random variables}


$('#check').click(function(){ // if we click 'Check correct answer button

    if(givenAnswer == correctAnswer)
    {
        $('#raisingCrystals').animate({ 
            'marginTop' : "-=51%", 
            'opacity' : '0.0'
            },2000, function(){
                $('#crystalsH3 > h3').html('+3'); 
                $('#crystalsH3 > h3').css('color','#0D5C94'); 
                $('#crystalsH3').animate({
                    'font-size' : "10vw"
                    },2000, function(){
                            $('#totalPoint > h3').html(totalPoints);
                            $('#speak4 > p').css('font-size','1.7vw');
                            $('#speak4 > p').html('Blaa blaa...');
                            $('#check > h2').html('---Next assesment---');

            // let's do a function that check, if the '---Next assesment---'-button is clicked

                    $('#check > h2').click(function newLevel(){
                            level++;
                        });     
                    });
                });
            });
        }
        else
        {

        }

    });
});

【问题讨论】:

  • 您最好提供简约样本来复制您的问题并更好地解释您的预期行为。首先,我猜你应该在点击处理程序中检查level,但我不确定因为你的代码实际上没有多大意义,不知道你在期待什么

标签: javascript jquery if-statement return


【解决方案1】:

用这个替换你的代码部分:

$('#check > h2').click(function () {
    level++;
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-20
    • 1970-01-01
    • 2011-12-08
    • 1970-01-01
    相关资源
    最近更新 更多