开发者

js is not defined error

开发者 https://www.devze.com 2023-02-25 07:15 出处:网络
How can I get the error message on a good way to solve? Error message: timetotal is not defined开发者_StackOverflow.

How can I get the error message on a good way to solve? Error message: timetotal is not defined开发者_StackOverflow.

 $(document).ready(function() {
    if (typeof(timeleft) !== 'undefined') {
        Chrono.update();
    }
    $('a.add_other_answer').click(function() {
        addAnswer();
    });
});

Chrono = {
    warning: timetotal * 0.25,
    critical: timetotal * 0.05,

    update: function() {
    ...
    ...


This seems pretty self-explanatory, even with your code example being incomplete.

timetotal is most likely undefined at this line, since it is passed as a property of the object Chrono:

warning: timetotal * 0.25,

You are most likely incrementing timetotal in your Chrono.update method, but that is too late: the property should have an initial value if you want to multiply it with 0.25 or 0.05.

Solution:

var timetotal = 0;

Chrono = {
    warning: timetotal * 0.25,
    critical: timetotal * 0.05,
0

精彩评论

暂无评论...
验证码 换一张
取 消