<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>计算器</title>
<script>
function calc() {
var x = parseInt(document.getElementById('sum1').value);
var y = parseInt(document.getElementById('sum2').value);
var fuhao = parseInt(document.getElementById('sym').value);
var he;
switch(fuhao){
case '+': he=x+y; break;
case '-': he=x-y; break;
case '*': he=x*y; break;
case '/': he=x/y; break;
}
document.getElementById('sum').value=he;
}
</script>
</head>
<body>
<input type="text" id="sum1">
<select name="" id="sym">
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select>
<input type="text" id="sum2">
<input type="button" value=" = " onclick="calc()">
<input type="text" id="sum">
</body>
</html>
慕后端6939749
倾夏秋冬
相关分类