当if语句为true时,FlipClock.js停止

时间:2014-10-22 08:12:41

标签: javascript jquery html5 flipclock

所以即时尝试创建一个简单的游戏,如果用户得到正确的答案,FlipClock.js将停止并记录用户获取正确答案的时间。

我在使用javascript时遇到了很多麻烦,我不知道如何调用fucntions来停止时钟。任何帮助将非常感谢。

当我运行此操作时,我收到一条错误消息,指出Uncaught TypeError:无法在控制台窗口中读取未定义的属性“stop”。

这是我的代码:

    <script type="text/javascript">
        var clock;

        $(document).ready(function() {
            var clock;

            clock = $('.clock').FlipClock(180, {
                clockFace: 'MinuteCounter',
                countdown: true,
                callbacks: {
                    stop: function() {
                        $('.message').html('Game Over!')
                    }
                }
            });

        });
    </script>



    <h1>LATEHENP</h1> <!-- ELEPHANT -->



<form id="inputForm">
<p>
<label for="userAnswer">Answer:</label>
<input id="userAsnwer" type="text" name="userAnswer" autocomplete="off" maxlength="8"/>
</p>
<input type="button" value="Submit" id="loginBtn"/>
</form>

<script type="text/javascript">



function process(){
    console.log("working");
        if(inputForm.userAnswer.value.toLowerCase()==="elephant")
    {   //Correct
     document.getElementById("message2").innerHTML = "Well done!";
         clock.stop();
         var time  = clock.getTime();
         console.log("time");

    }
    else
    {
        //Incorrect
    document.getElementById("message2").innerHTML = "Incorrect! <a href='javascript:location.reload(true)'>Retry?</a> ";
    }
};


var btn = document.getElementById("loginBtn");
btn.addEventListener("click", process, false);

</script>

1 个答案:

答案 0 :(得分:0)

看起来你正试图在选项区域中定义stop方法。

我会在设置var clock的片段之外定义clock.stop作为时钟对象的实例化。然后在提交页面后关闭您的process()函数。

相关问题