<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title></title> <script type="text/javascript"> var numresult; var str; function onclicknum(nums) { str = document.getElementById("nummessege"); str.value = str.value + nums; } function onclickclear() { str = document.getElementById("nummessege"); str.value = ""; } function onclickresult() { str = document.getElementById("nummessege"); numresult = eval(str.value); str.value = numresult; } </script> </head> <body bgcolor="affff"> <!--定义按键表格,每个按键对应一个事件触发--> <table bgColor="#bbff77"> <tr> <td colspan="4"> <input type="text" /> </td> </tr> <tr> <td> <input type="button" value="1"> </td> <td> <input type="button" value="2"> </td> <td> <input type="button" value="3"> </td> <td> <input type="button" value="+"> </td> </tr> <tr> <td> <input type="button" value="4"> </td> <td> <input type="button" value="5"> </td> <td> <input type="button" value="6"> </td> <td> <input type="button" value="-"> </td> </tr> <tr> <td> <input type="button" value="7"> </td> <td> <input type="button" value="8"> </td> <td> <input type="button" value="9"> </td> <td> <input type="button" value="*"> </td> </tr> <tr> <td colspan="2"> <input type="button" value="0"> </td> <td> <input type="button" value="."> </td> <td> <input type="button" value="https://www.jb51.net/"> </td> </tr> <tr> <td colspan="2"> <input type="button" value="Del" /> </td> <td colspan="2"> <input type="button" value="=" /> </td> </tr> </table> </body> </html>
效果图