js html实现计算器功能

<!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>

效果图

js html实现计算器功能

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/b2eb892f29185261184cab72ebff5a2e.html