gpt4 book ai didi

javascript - 为什么使用 && 的 IF 条件在 JavaScript 中不起作用?

转载 作者:行者123 更新时间:2023-12-03 00:33:51 24 4
gpt4 key购买 nike

我在 javascript 中使用 && 的 if 条件时遇到问题。条件语句不起作用,我不知道为什么。代码如下:

<script type = 'text/javascript'>
function computeLoan(){
var leasing = document.getElementById('leasing').value; // the data are taken from select option in HTML
var tenor = parseInt(document.getElementById('tenor').value); // the data are taken from select option in HTML
var ten = tenor/2;
var otr = document.getElementById('otr').value;
var dp = document.getElementById('dp').value;
// var total = 0;

if ((leasing = "PT. Adira Dinamika Multi Finance, Tbk") && (tenor == "24"))
{
interest = 0.039;
}
if ((leasing = "PT. Adira Dinamika Multi Finance, Tbk") && (tenor == "36"))
{
interest = 0.042;
}
if ((leasing == "PT. Wahana Ottomitra Multiartha (WOM)") && (tenor == '24'))
{
interest = 0.036;
}
if ((leasing == "PT. Wahana Ottomitra Multiartha (WOM)") && (tenor == '36'))
{
interest = 0.041;
}
if ((leasing == "PT. Summit Oto Finance") && (tenor == '24')) {
interest = 0.0355;
}
if ((leasing == "PT. Summit Oto Finance") && (tenor == '36')) {
interest = 0.04;
}

total = (((otr - dp) * interest * ten) + (otr - dp))/tenor;
$("#monthly").val(total);

}
</script>

最佳答案

问题出在第一个 if 语句:

if ((leasing = "PT. Adira Dinamika Multi Finance, Tbk") && (tenor == "24")) 

它说的地方

leasing = "PT. Adira Dinamika Multi Finance, Tbk"

您使用了错误的 = 符号 - 它应该是 ==。 = 是变量赋值运算符,== 是等价运算符。修复 if 语句,使其看起来像这样:

if ((leasing == "PT. Adira Dinamika Multi Finance, Tbk") && (tenor == "24")) 

你的代码将会工作。

关于javascript - 为什么使用 && 的 IF 条件在 JavaScript 中不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53736160/

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