简体   繁体   English

"if 语句不起作用 - 当技能点低于 0 时脚本不会停止"

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

I have if statement that doesn't work.我有 if 语句不起作用。

I want the script to stop working when the skillpoints are 0 or below.我希望脚本在技能点为 0 或以下时停止工作。

My code:我的代码:

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:您必须将 if 条件放入您的点击处理程序中,如下所示:

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

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

"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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