HTML 代码(Calculator.html):
<!DOCTYPE html>
<html>
<head
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Calculator</title>
<link type="text/css" rel="stylesheet" href="Calculator_CSS.css">
</head>
<body>
<input type ="text" name="number1" style="width:50px;" id="Number1">
<select id="DropdownMenu1">
<option>+</option>
<option>-</option>
<option>×</option>
<option>÷</option>
</select>
<input type ="text" name="number2" style="width:50px;" id="Number2">
<input type="button" value="Calculate" id="submitButton" />
<p>The answer is: <span id="answer"></span></p>
<script src="Calculator_JS.js>"></script>
</body>
</html>
这是 JavaScript 代码(Calculator_JS.js):
var button = document.getElementById("submitButton");
button.onclick = function(){
if (document.getElementById("DropdownMenu1").value == "+"){
var num1 = document.getElementById('Number1').value;
var num2 = document.getElementById('Number2').value;
var answer = num1 + num2;
document.getElementById('Answer').value = answer;
}
}
出于某种原因,当我单击计算按钮时,它什么也没做。任何帮助都会很棒!谢谢!