简体   繁体   中英

if statement does not work - script doesn't stop when skillpoints are below 0

I have if statement that doesn't work.

var skillpoints = 5;

        if (skillpoints > 0) {

            // Dodawanie skillpointów
        
            $('.str .stat-plus img').click(function() {
                var val = $('.str-img div').text();
                var new_val = parseInt($('.str-img div').text(),10) + 1 ;
                $('.str-img div').text(new_val);
                $('.str input').val(new_val);
                skillpoints--;
                $('.skillpoints').text(skillpoints);
                $('.register-skillpoints').val(skillpoints);
            });
    }

You have to put the if condition into your click handler, like this:

$('.str .stat-plus img').click(function() {
  if (skillpoints > 0) {
    // etc
  }
}

我还添加了相同的 if 到点击功能,现在它可以工作了;)

"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM