我的 HTML 计算器不会显示输入或结果。如果可能的话,我想保留我的布局和设计。我只用 HTML 代码制作了这个计算器。我希望它是在一个预先存在的网站上的基础。我尝试过使用 JavaScript 和 jQuery,但我对它的理解还不够好,无法让它运行。我也尝试了一些调试软件,但他们还没有缩小问题的范围。
HTML计算器的代码:
body {
background-color: #FFFFFF;
background-size: 1500px;
}
#calculator {
width: 250px;
height: 375px;
text-align: center;
margin: 90px auto;
box-shadow: 10px 10px 10px #010012;
background-color: #229EE2;
background-size: 7px;
border-radius: 30px;
border: 3px solid #595959;
}
#display {
margin: 30px 0 20px 0;
padding-right: 2%;
width: 220px;
height: 30px;
border-radius: 4px;
box-shadow: 0px 0px 3px #595959;
text-align: right;
font: 27px bold;
color: #1A3C67;
background-color: #78c4ed;
}
#keys {
width: 43px;
height: 35px;
margin-left: 10px;
margin-bottom: 20px;
box-shadow: 0px 0px 15px #010012;
cursor: pointer;
font-style: italic;
color: lightblue;
background-color: rgb(0, 50, 68);
font-weight: bold;
font-size: 24px;
border-radius: 4px;
}
#keys:hover {
background: #1998cd;
font-weight: bold;
color: #1e185e;
}
#keysC {
width: 43px;
height: 35px;
margin-left: 10px;
margin-bottom: 20px;
box-shadow: 0px 0px 10px #595959;
cursor: pointer;
font-style: italic;
color: #1A3C67;
background-color: lightblue;
font-weight: bold;
font-size: 16px;
border-radius: 4px;
}
#keysC:hover {
background: #7caad0;
font-weight: bold;
color: #1A3C67;
}
<html>
<head>
<title>Financial Calculator</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div id="calculator">
<div class="fluid-container">
<form name="Financial Calculator">
<input type="textfield" id="display" name="ans" value="" class="form-control" placeholder="">
<br>
<div class="row">
<div>
<input type="reset" id="keysC" value="C">
<input type="reset" id="keysC" value="CE">
<input type="button" id="keysC" value="<--">
<input type="button" id="keysC" value="%" onClick="document.calculator.ans.value+='%'">
</div>
</div>
<br>
<input type="button" id="keys" value="7" onClick="document.calculator.ans.value+='7'">
<input type="button" id="keys" value="8" onClick="document.calculator.ans.value+='8'">
<input type="button" id="keys" value="9" onClick="document.calculator.ans.value+='9'">
<input type="button" id="keysC" value="/" onClick="document.calculator.ans.value+='/'">
<br>
<input type="button" id="keys" value="4" onClick="document.calculator.ans.value+='4'">
<input type="button" id="keys" value="5" onClick="document.calculator.ans.value+='5'">
<input type="button" id="keys" value="6" onClick="document.calculator.ans.value+='6'">
<input type="button" id="keysC" value="*" onClick="document.calculator.ans.value+='*'">
<br>
<input type="button" id="keys" value="1" onClick="document.calculator.ans.value+='1'">
<input type="button" id="keys" value="2" onClick="document.calculator.ans.value+='2'">
<input type="button" id="keys" value="3" onClick="document.calculator.ans.value+='3'">
<input type="button" id="keysC" value="-" onClick="document.calculator.ans.value+='-'">
<br>
<input type="button" id="keys" value="0" onClick="document.calculator.ans.value+='0'">
<input type="button" id="keys" value="." onClick="document.calculator.ans.value+='.'">
<input type="button" id="keys" value="=" onClick="document.calculator.ans.value=eval(document.calculator.ans.value)">
<input type="button" id="keysC" value="+" onClick="document.calculator.ans.value+='+'">
</form>
</div>
</div>
</body>
</html>