首页 > 解决方案 > 如果语句没有在 wix 上运行计算,我是否遗漏了一些明显的东西?

问题描述

我是初学者,无法弄清楚为什么我的 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)

标签: javascriptvelo

解决方案


value returned is in string format and your if statement is comparing with numbers because of which none of your if statements evaluates to truthy value. First convert the input value in number/integer type and then make comparison

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

推荐阅读