【问题标题】:How to use conditional statements如何使用条件语句
【发布时间】:2014-11-25 15:51:41
【问题描述】:

所以我正在使用这个代码:

//You should replace this "true" with your right condition(in accordance to your logic).
var condition = true;
if(condition){
   //Run create service.
   checkbox.execute();
}
else{
   //Run udpate service.
   check_update.execute();
}

我希望在第一次单击按钮时执行复选框...如上所述。从那里开始,我希望它执行 check_update。

关于“var condition = true”应该是什么的任何想法?

【问题讨论】:

    标签: conditional conditional-statements


    【解决方案1】:

    如何创建一个变量来存储按钮是否第一次被点击:

    var first_time = true;
    
    if (first_time) {
        // Run create service.
        checkbox.execute();
    
        first_time = false;
    } else {
        // Run udpate service.
        check_update.execute();
    }
    

    如果这是 Javascript,您还必须了解此变量的范围。

    【讨论】:

    • 我认为它没有识别出它的第一次部分,因为我重复运行创建服务而不是只运行一次。还有其他想法吗?
    • @EllenSchlechter 如果此代码在函数中,您需要将first_time(第一行)的变量声明移到它之外。否则,每次函数以true 运行时都会重新声明它。如果您可以发布更多相关代码,它可能会有所帮助。
    猜你喜欢
    • 2011-01-08
    • 1970-01-01
    • 2017-03-23
    • 2011-06-21
    • 2021-02-22
    • 2018-04-04
    • 2020-07-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多