javascript - 如果语句没有在 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)
解决方案
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);
推荐阅读
- javascript - redux withrouter 不适用于反应。它将呈现新页面,但不会使用新状态/道具呈现
- swift - 使 AR 视频适应背景
- python - 使用 Python 加速并行读取大文件
- google-analytics - 唯一购买和数量相同
- kotlin - 在 Flux 中从一个元素生成两个元素?
- javascript - 如何使用附加了 ajax 的触发器删除附加数据?
- gltf - 如何以编程方式为给定的 GLTF 文件生成全景图像(360 度图像)?
- android - Grid Recyclerview 消失的项目,两个项目之间有一个空白单元格
- ios - 如何确定我面对的是节点
- java - 无法使用 resttemplate 使用 rest api