
- html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>title>
- head>
- <style>
- .box {
- height: 570px;
- width: 500px;
- background-color: deeppink;
- margin: auto;
- border-radius: 10px;
- border: 3px solid black;
- }
-
- .dtable {
- height: 560px;
- width: 460px;
- margin: auto;
- }
-
- #txt {
- height: 70px;
- width: 300px;
- font-size: 50px;
- font-family: "黑体";
- font-weight: 200px;
- border: 2px solid black;
- }
-
- td {
- text-align: center;
- font-size: 20px;
- font-weight: 200;
- margin: auto;
- padding: auto;
- }
-
- .point {
- height: 80px;
- width: 97px;
- text-align: center;
- padding: auto;
- margin: auto;
- border-radius: 10px;
- border: 2px solid black;
- background-color: hotpink;
- cursor: pointer;
- font-size: 60px;
- font-family: "黑体";
- }
-
- .point:hover {
- background-color: lightpink;
- }
- style>
- <body>
- <div class="box">
- <table class="dtable">
- <tr>
- <td colspan="3" class="rdt">
- <input type="text" id="txt" value="" readonly />
- td>
- <td>
- <img src="img/rabbit.gif" alt="">
- td>
- tr>
- <tr>
- <td>
- <div class="point" onclick="fun('9')">9div>
- td>
- <td>
- <div class="point" onclick="fun('8')">8div>
- td>
- <td>
- <div class="point" onclick="fun('7')">7div>
- td>
- <td>
- <div class="point" onclick="fun('+')">+div>
- td>
- tr>
- <tr>
- <td>
- <div class="point" onclick="fun('6')">6div>
- td>
- <td>
- <div class="point" onclick="fun('5')">5div>
- td>
- <td>
- <div class="point" onclick="fun('4')">4div>
- td>
- <td>
- <div class="point" onclick="fun('-')">-div>
- td>
- tr>
- <tr>
- <td>
- <div class="point" onclick="fun('3')">3div>
- td>
- <td>
- <div class="point" onclick="fun('2')">2div>
- td>
- <td>
- <div class="point" onclick="fun('1')">1div>
- td>
- <td>
- <div class="point" onclick="fun('*')">×div>
- td>
- tr>
- <tr>
- <td>
- <div class="point" onclick="fun('0')">0div>
- td>
- <td>
- <div class="point" onclick="fun('C')">Cdiv>
- td>
- <td>
- <div class="point" onclick="fun('=')">=div>
- td>
- <td>
- <div class="point" onclick="fun('/')">÷div>
- td>
- tr>
- table>
- div>
- <script>
- var s = '';
-
- function fun(value) {
- var txt = document.getElementById("txt");
- if (value === 'C') {
- s = '';
- } else if (value === '=') {
- s = eval(s);
- } else if (value === '+' || value === '*' || value === '/' || value === '-') {
- if (s[s.length - 1] === '+' || s[s.length - 1] === '*' || s[s.length - 1] === '/' || s[s.length - 1] ===
- '-') {
- s=s.substr(0,s.length-1);
- s+=value;
- } else s += value;
- } else {
- s += value;
- }
- if (s == "Infinity") txt.value = "分母不为0!";
- else if (s == "Undefined") txt.value = "请输入正确数字!";
- else txt.value = s;
- // alert(s);
-
- }
- script>
- body>
- html>