首页 > 解决方案 > jQuery:基于常量值的验证,例如(+50 或 -50)具有相同货币的常量值

问题描述

有这样的要求,例如我需要将一个阈值与总值(计数)的总和进行比较,并且如果阈值+50 or -50和所选记录具有相同的货币,则将根据阈值进行比较。需要做成功的验证。如果超过+50 or -50不允许成功验证。

我尝试了以下验证,它通过+50(通过)并在-50(失败)验证中失败。

var theresholdVal = 50;
for (let i = 0; i < jsonData1.length; i++) {
    for (let j = 0; j < jsonData2.length; j++) {
        if (jsonData1[i]['Currency'] !== jsonData2[j]['Currency']) {
            alert("Currency is mismatched, please select same currency!!!");
            return false;
        } else if (theresholdVal <= parseInt(countVal)) {
            alert("Selected value is more thereshold value");
            return false;
        } else {
            alert("Data matched successfully!!!");
        }
    }
}

小提琴

标签: javascriptjquery

解决方案


推荐阅读