我是JS的新手,我已经在线查看,但我仍然不确定为什么我会收到这些错误。我有一个index.html和一个CSS表。 JS似乎有问题,但我无法弄清楚原因。
用户应输入一些值,单击按钮,然后该功能应触发并更改"结果" div元素。
的index.html
<html>
<head>
<title>Out of Shield Options</title>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="styles/main.css"
</head>
<body>
<h1>Out of Shield</h1>
<div class="navbar">
<ul>
<li>Home</li>
<li><a href="faq.html">FAQ</a></li>
<li><a href="contact.html">Contact Us</a></li>
</ul>
</div>
<h2>Calculator</h2>
<div id="inputInfo">
<div class="inputLabel">
<label>Hit Frame:</label><input type="text" class ="textField" id="hitFrame" class="inputs" value="0"></input>
</div>
<div class="inputLabel">
<label>IASA Frame:</label><input type="text" class ="textField" id="iasaFrame" class="inputs" value="0"></input>
</div>
<div class="inputLabel">
<label>Damage:</label><input type="text" class ="textField" id="damage" class="inputs" value="0"></input>
</div>
<div class="submit"><input id="calculateButton"type="button" value="Calculate!" onclick="calculateAdvantage()"></div>
<div id="result"></div>
</div>
<script>
calculateAdvantage(){
var hitFrame = document.getElementById("hitFrame");
var IASA = document.getElementById("iasaFrame");
var damage = document.getElementById("damage");
var shieldStun = (damage / 1.75) + 2;
var result = IASA - hitFrame - shieldStun;
document.getElementById("calculateButton").innerHTML = result;
}
</script>
</body>
</html>
答案 0 :(得分:2)
您必须将calculateAdvantage
声明为函数:
function calculateAdvantage() {
// Your code goes there
}