开发者

Trying to add/subtract variable

开发者 https://www.devze.com 2023-03-11 17:13 出处:网络
I am trying to have something where when it is enabled it adds to a variable and when it is disabled it subtracts from the variable but when I alert the value of the variable is just comes up saying N

I am trying to have something where when it is enabled it adds to a variable and when it is disabled it subtracts from the variable but when I alert the value of the variable is just comes up saying NaN Here is my code:

This is for enabling/disabling the button

var speedrating;
function onoffButton(i, g, r)
{
    $(i).click(function () {
        if ($(i).html() == '<a class="onoffswitch" id="' + g + 'ON"></a>') {
            $(i).html('<a class="onoffswitch" id="' + g + 'OFF"></a>');
            speedrating -= r;
        } else {
            speedrating += r;
            $(i).html('<a class="onoffswitch" id="' + g + 'ON"></a>');
        }
        updateSpeedRate();
    });
}

Here is where it checks the variable to see which thing to do:

function updateSpeedRate()
{
    if (speedrating < 34) {
        $('.speedmeter').css('background-position', '0px -30px');
    } else {
        if (speedrating < 67) {
            $('.speedmeter').css('background-position', '0px -15px');
        } else {
            $('.speedmeter').css('background-position', '0px 0px开发者_开发百科');
        }
    }
    alert(speedrating);
}

Then using the enable/disable object (the third number is the number I'm trying to work with):

onoffButton("#switchRating", "rating", 10);

onoffButton("#switchFavicon", "favicon", 30);

onoffButton("#switchClock", "clockswitch", 10);

onoffButton("#switchWeather", "weatherswitch", 30);

onoffButton("#switchNotepad", "notepadswitch", 15);

onoffButton("#switchLinks", "linksswitch", 5);


You will need to give speedRating a value before you add/subtract from it

var speedrating = 0;

0

精彩评论

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