作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
它只显示 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/
我是一名优秀的程序员,十分优秀!