gpt4 book ai didi

javascript - If, else if 语句不起作用(仅显示 if)

转载 作者:行者123 更新时间:2023-12-03 02:57:29 29 4
gpt4 key购买 nike

它只显示 if 语句。没有到达第二或第三条语句。 HTML 部分仅显示“commentE”值。

var totalAmount = (conversion * sAmount);
totalAmount = $("#totalAmount").val(totalAmount);

var myadvice;
myadvice = $("#myadvice").val();

var great;
great = localStorage.getItem("great");

var commentE;
commentE = localStorage.getItem("commentE");

var between;
between = localStorage.getItem("between");

var betweenb;
betweenb = localStorage.getItem("betweenb");

var commentB;
commentB = localStorage.getItem("commentB");

var less;
less = localStorage.getItem("less");

var commentL;
commentL = localStorage.getItem("commentL");

if (totalAmount >= great) {
myadvice = $("#myadvice").val(commentE);
} else if ((totalAmount >= between) && (totalAmount <= betweenb)) {
myadvice = $("#myadvice").val(commentB);
} else if (totalAmount <= less) {
myadvice = $("#myadvice").val(commentL);

这些是 HTML 部分(用于获取输入的索引页)

<div data-role="navbar">
<ul>
<li>
<label for="between">Between</label>
<div class="ui-grid-a">
<div class="ui-block-a">
<input type="text"
name="between" id="between" placeholder="between" value="200">
</div>
<div class="ui-block-b">
<input type="text"
name="betweenb" id="betweenb" placeholder="between" value="499">
</div>
</div>
</li>
<li>
<label for="commentB">Comment</label>
<input type="text" name="commentB"
id="commentB" placeholder="comments" value="OK">
</li>
</ul>
</div>

这些应该是结果(结果页面显示上一页的输入

    <div data-role="main" class="ui-content">
<div class="ui-field-contain">
<div data-role="fieldcontainer">
<label for="advice"> My Advice is as follows: </label>
<input type="text" name="advice" id="advice">
</div>
</div>
</div>
</b>

最佳答案

If else 语句为 executed in order ,例如:

total = 10;
greater = 5;
between = 4;
if(total >= greater) {
console.log("comment a");
} else if (total >= between) {
console.log("comment b");
}

结果将是comment a,因为在total >= Between之前尝试了total >= Greater。两个语句都是 true,但首先尝试第一个语句,并且只执行一个语句的内容。运行 if else 语句内的代码后,执行的下一个内容位于 if else 组下方。

关于javascript - If, else if 语句不起作用(仅显示 if),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47556567/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com