你好不能让我的“if”声明工作。当我写我的整个功能停止工作。没有if,一切正常。
我尝试了一切,至少我能想到的一切,这意味着使用parseInt,if / else,我一遍又一遍地阅读代码,我更改了括号,我研究了谷歌。依然没有。我需要一些帮助!
function myF() {
var num1 = document.getElementById("a").value;
var num2 = document.getElementById("b").value;
var num3 = document.getElementById("c").value;
var num4 = document.getElementById("d").value;
var num5 = document.getElementById("e").value;
var num6 = document.getElementById("f").value;
var num7 = document.getElementById("g").value;
var num8 = document.getElementById("h").value;
var num9 = document.getElementById("i").value;
if (isNaN(num1) || num1 = "") {
num1 === 0;
}
var total = parseFloat(num1)+ parseFloat(num2)+parseFloat(num3)+parseFloat(num4)+parseFloat(num5)+parseFloat(num6)+parseFloat(num7)+parseFloat(num8)+parseFloat(num9);
var floating2 = document.getElementById("result").value = total.toFixed(2);
}
body {
background: url(img/Construction-Wallpaper-8.jpg) repeat-y center center;
background-size: 100% 100%;
}
form {
width: 530px;
align-content: center;
margin:45px auto 5px;
border: solid 1px darkslategrey;
padding: 10px 0px 10px 5px;
display: block;
}
input {
float: right;
clear: both;
position: relative;
top: -4;
}
label {
padding: 8px 10px;
font-family: Montauk, arial, sans-serif;
font-size: 18px;
font-weight: bolder;
color: black;
display: block;
}
input#result {
position: relative;
right: 10px;
top: 6px;
}
button#Total {
position: relative;
left: 10px;
top: 2px;
background: linear-gradient(to right, darkslategrey, white);
font-family: Montauk, arial, sans-serif;
font-size: 29px;
font-weight: bold;
width: 100px;
height: 30;
text-align: left;
line-height: 100%;
box-shadow: 1px 1px 3px;
border: solid 1px black;
}
button#total:active {
position: relative;
top: 1px;
right: 1px;
}
button#total:hover {
cursor: pointer;
}
p#title {
font-size: 50px;
text-align: center;
margin: 10px;
font-family: Montauk, arial, sans-serif; color: #333;
font-weight: bolder
}
img#Logo {
width: 70px;
display: inline-block;
position: absolute;
top:15px;
right: 9px;
}
p#Logo {
font-family: "Montauk", arial, sans-serif;
font-size: 20px;
display: inline-block;
width: 50px;
height: 30px;
position: absolute;
top:-2px;
right: 105px;
}
label::after {
float: right;
content: "$";
font-size: 25px;
display: inline-block;
position: relative;
right: 3px;
bottom: 5px;
}
#total::before {
content: "$";
font-size: 25px;
position: relative;
left:290px;
font-family: Montauk, arial, sans-serif;
font-weight: bolder;
}
<html>
<head>
<title>Payment Schedule</title>
<link rel="stylesheet" href="zzz.css" type="text/css">
<link rel="stylesheet" href="normalize.css" type="text/css">
</head>
<body id="body">
<p id="title">• Payment Schedule •</p>
<div id="companyName">
<p id="Logo">Christopher
Crawford
Const.</p>
<img src="img/Logo_Crawford1ps.png" id="Logo">
</div>
<form id="sumNumbers">
<label >I.Downpayment 5/14 <input id="a" type="text"></label>
<label >II.Progress payment end of week2, @15% <input id="b" type="text"> </label>
<label >III.Progress payment end of week4, @15% <input id="c" type="text"></label>
<label >IV.Progress payment end of week6, @15% <input id="d" type="text"></label>
<label >V.Progress payment end of week8, @15% <input id="e" type="text"></label>
<label >VI.Progress payment end of week10, @15% <input id="f" type="text"></label>
<label >VII.Progress payment end of week11, @7.5% <input id="g" type="text"></label>
<label >VIII.Progress payment end of week12, @7.5% <input id="h" type="text"></label>
<label >IX.Final Payment @10% <input id="i" type="text"></label>
<button id="total" onclick="myF();" type="button">Total</button>
<input type="text" id="result">
</form>
</body>
</html>
答案 0 :(得分:0)
在if
语句中,您应该使用===
来测试是否相等。 =
是赋值运算符,您应该在下面的行中,即num1 = 0;
。