<!DOCTYPE html>
<html>
<head>
<title>简单计算器</title>
<style>
.jisuanqi{
text-align: center;
margin-top: 50px;
}
</style>
<script type="text/javascript">
function count(){
var a = document.getElementById("txt1").value;
var b = document.getElementById("txt2").value;
var c = document.getElementById("select").value;
a = parseFloat(a);
b = parseFloat(b);
switch(c){
case "+":
document.getElementById("fruit").value=parseInt(a)+parseInt(b);
break;
case "-":
document.getElementById("fruit").value=parseInt(a)-parseInt(b);
break;
case "*":
ocument.getElementById("fruit").value=parseInt(a)*parseInt(b);
break;
case "/":
document.getElementById("fruit").value=parseInt(a)/parseInt(b);
break;
}
}
</script>
</head>
<body>
<div class="jisuanqi">
<h2>简单计算器</h2>
<input type='text' id='txt1'/>
<select id='select'>
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select>
<input type='text' id='txt2'/>
<input type='button' value='=' onclick = "count()"/>
<input type='text' id='fruit'/>
</div>
</body>
</html>
简单计算器.png
网友评论