gpt4 book ai didi

javascript - 如果 isNaN,如何将变量的内容更改为零

转载 作者:行者123 更新时间:2023-11-30 09:02:54 25 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
When I press enter I get isNaN, but the value is a number

我上周日交了作业。由于 isNaN 值返回到 Total 文本框,所以它被发回给我进行更正。我认为这就是编程要做的事情。相反,根据她的说法,“isNaN 函数将检查变量并确定变量是否包含非数字数据,然后下一条语句将更改变量的内容以设置为零,”这让我感到困惑。任何建议这是代码。 *返回;”在我进行更改之前,语句不是语法错误。这是上传文件的链接:ciswebs.smc.edu/cis54/tyson_schweidel/homework2.htm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Price Calculator</title>
<script type="text/javascript">

function fixOrder()
{
var numPrice = parseFloat(document.getElementById("cost").value);
var taxP = parseFloat(document.getElementById("tax").value);
var total = parseFloat(document.getElementById("total").value);

}

if (isNaN(numPrice)){

alert("Sorry,you must enter a numeric value to place order");

if (isNaN(taxP))
alert("Sorry, you must enter a numeric tax value to continue");
return; //gets syntax error
}


var tax = (numPrice * taxP)/100;{
var total = numPrice + tax;
numPrice = 0;
taxP = 0;
document.getElementById("total").value = "$" + total.toFixed(2);
return; //gets syntax error
}
</script>

</head>

<body bgcolor="#00f3F1">


<h1 align="left">Price Calculator</h1>

<form name="form">
<p>
Price: <input type="text" id="cost" name="cost" value="" onchange="fixOrder();"/>
</p>
<p>
Tax: &nbsp;
<input type="text" id="tax" name="tax" value="" onchange="fixOrder();"/>
</p>
<p>
Total:
<input type="text" id="total" name="total" value="" disabled="disabled();"/>
</p>
</form>

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