【问题标题】:if statement not running calculation on wix, am I missing something obvious?如果语句没有在 wix 上运行计算,我是否遗漏了一些明显的东西?
【发布时间】:2019-03-16 13:55:48
【问题描述】:

我是初学者,不知道为什么我的 if 语句不起作用。我正在使用 wixcode 和 javascript。下面的每个 if 语句都显示了我尝试运行计算的不同方式。作为 SR 输入的数字显示在 onClick 文本框中,但不运行计算来操作输入数字,或者它可能没有一起运行 if 语句。我错过了什么明显的东西吗?

    $w.onReady(function () {
$w("#generatequote").onClick((event) => {

    var SR = $w("#SR").value;
    if (SR<100) {
        $w("#SR").value = SR *2
        //example one. Tried making it write the input * 2 if the input number is less than 100
    }
    else if (SR>=100&&SR<300) {
        $w("#SR").value = ("#SR")*1.5;
        //example two. Tried making it write the input * 1.5 if the input number is between 100 and 300
    }
    else if (SR>=300&&SR<600) {
        $w("#SR").value * 1.25;
        //example three. Tried making it write the input * 1.25 if the input is between 300 and 600
    }
    else if(SR>=600) {
        $w("#SR").value = ("SR");
    }

    $w("#quotetext").value =(SR)

【问题讨论】:

  • 它不运行任何语句吗? onClick 还能用吗?
  • 我希望您的代码末尾有匹配的 }),因为它没有在您的示例中显示
  • onClick 确实有效,但它不运行任何语句。我确实在代码末尾有 }),我只是忘记将它包含在示例中,因为它是在给我自己的一堆注释之后出现的。对此感到抱歉。

标签: javascript velo


【解决方案1】:

value 返回的是string 格式,并且您的 if 语句正在与 numbers 进行比较,因此您的 if 语句都没有评估为真实值。先将输入值转换成number/integer类型再进行比较

var SR = Number($w("#SR").value);

【讨论】:

    猜你喜欢
    • 2011-12-28
    • 1970-01-01
    • 1970-01-01
    • 2013-07-12
    • 2014-06-07
    • 2015-02-16
    • 2011-05-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多