html+js实现的简单计算器(加减乘除)
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body>
<table>
<tr>
<td><input type="button" value="add"    οnclick="setOp('+', 'add');"/></td>
<td><input type="button" value="miner"  οnclick="setOp('-', 'miner');"/></td>
<td><input type="button" value="times"  οnclick="setOp('*', 'times');"/></td>
<td><input type="button" value="divide" οnclick="setOp('/', 'divide');"/></td>
</tr>
</table>
<table id="tb_calc" >
<tr>
<td> <input id="x" type="text" value="" name="x" /></td>
<td> <lable id="op"  name="op"></lable> </td>
<td> <input id="y" type="text" value="" name="y" /> </td>
<td> <input id="opTips" type="button" value="" οnclick="calc();"/> </td>
<td> <lable id="z" name="z"></lable> </td>
</tr>
</table>
<script type="application/javascript">
function setOp(op, opTips)
{
var ElementById("tb_calc");
tb.style.display = "none";
tb.style.display = "block";
}
function calc()
{
var x  = ElementById("x").value);
var y  = ElementById("y").value);
var op = ElementById("op").innerText;
var z = "";
switch(op)
{
case '+':
z = x + y;
javascript计算器代码
break;
case '-':
z = x - y;
break;
case '*': ;
z = x * y;
break;
case '/': ;
z = x / y;
break;
default:
z = '';
}
}
console.log(x, op, y, '=', z);
</script>
</body>
</html>
截图如下:

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。