先看效果:
其实写这个挺简单的计算用了一个table布局。没有其他的复杂的布局。。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>计算器</title> <body> <table align="center"> <tr> <td colspan="4"><input type="text" id="input" readonly="readonly"></td> </tr> <tr> <td colspan="4"><input type="text" id="result" readonly="readonly" ></td> </tr> <tr> <td colspan="2"><button class="AC" onclick="buttonCClicked()">AC</button></td> <td><button id="del" onclick="buttonDelClicked()">Ce</button></td> <td><button class="operation" onclick="buttonOperaClicked('/')">/</button></td> </tr> <tr> <td><button class="number" onclick="buttonNumberClicked(7)">7</button></td> <td><button class="number" onclick="buttonNumberClicked(8)">8</button></td> <td><button class="number" onclick="buttonNumberClicked(9)">9</button></td> <td><button class="operation" onclick="buttonOperaClicked('*')">*</button></td> </tr> <tr> <td><button class="number" onclick="buttonNumberClicked(4)">4</button></td> <td><button class="number" onclick="buttonNumberClicked(5)">5</button></td> <td><button class="number" onclick="buttonNumberClicked(6)">6</button></td> <td><button class="operation" onclick="buttonOperaClicked('+')">+</button></td> </tr> <tr> <td><button class="number" onclick="buttonNumberClicked(1)">1</button></td> <td><button class="number" onclick="buttonNumberClicked(2)">2</button></td> <td><button class="number" onclick="buttonNumberClicked(3)">3</button></td> <td><button class="operation" onclick="buttonOperaClicked('-')">-</button></td> </tr> <tr> <td colspan="2"><button class="number zero" onclick="buttonNumberClicked(0)">0</button></td> <td><button class="point" onclick="buttonPointClicked()">0</button></td> <td><button class="operation" onclick="buttonEqualClicked()">=</button></td> </tr> </table> </body> </head> <style> body{ background-color: black; } td > button{ height: 50px; width: 50px; border-radius: 50%; font-size: 30px; text-align: center; background-color: rgba(226, 225, 223, 0.932); color: white; } .AC{ height: 50px; width: 100px; } .zero{ height: 50px; width: 100px; } #result ,#input{ background-color: black; height: 50px; width: 200px; resize: none; border-color: black; color: white; font-size: 25px; text-align: end; } .number{ background-color: rgb(100, 100, 100); color: white; } .operation,.point{ background-color: orange; color: white; } </style>
|
1 2
| javascript自己写吧!因为一些原因不能发出来,可以去搜索一下
|