可以实现基本的加减乘除,三角函数,对数,指数,阶乘,开根号,实现效果如下图:
1.HTML代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="style.css">
<script src="index.js"></script>
</head>
<body>
<div id="calculator">
<div id="input">
<input type="text" id="Screen" name="Screen" class="screen" value="" readonly>
</div>
<div id="keys">
<input type="button" id="square" onclick="square()" value="x^2" />
<input type="button" id="cube" onclick="cube()" value="x^3" />
<input type="button" id="^" onclick="cal(this.id)" value="^" />
<input type="button" id="factorial" onclick="factorial()" value="n!" />
<input type="button" id="sin" onclick="sin()" value="sin" />
<input type="button" id="cos" onclick="cos()" value="cos" />
<input type="button" id="tan" onclick="tan()" value="tan" />