js html實(shí)現(xiàn)計(jì)算器功能
更新時(shí)間:2018年11月13日 17:01:44 作者:~李疆
這篇文章主要為大家詳細(xì)介紹了js html實(shí)現(xiàn)計(jì)算器功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
本文實(shí)例為大家分享了html實(shí)現(xiàn)計(jì)算器功能的具體代碼,供大家參考,具體內(nèi)容如下
代碼:
<!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"> <!--定義按鍵表格,每個(gè)按鍵對應(yīng)一個(gè)事件觸發(fā)--> <table border="1" align="center" bgColor="#bbff77" style="height: 350px; width: 270px"> <tr> <td colspan="4"> <input type="text" id="nummessege" style="height: 90px; width: 350px; font-size: 50px" /> </td> </tr> <tr> <td> <input type="button" value="1" id="1" onclick="onclicknum(1)" style="height: 70px; width: 90px; font-size: 35px"> </td> <td> <input type="button" value="2" id="2" onclick="onclicknum(2)" style="height: 70px; width: 90px; font-size: 35px"> </td> <td> <input type="button" value="3" id="3" onclick="onclicknum(3)" style="height: 70px; width: 90px; font-size: 35px"> </td> <td> <input type="button" value="+" id="add" onclick="onclicknum('+')" style="height: 70px; width: 90px; font-size: 35px"> </td> </tr> <tr> <td> <input type="button" value="4" id="4" onclick="onclicknum(4)" style="height: 70px; width: 90px; font-size: 35px"> </td> <td> <input type="button" value="5" id="5" onclick="onclicknum(5)" style="height: 70px; width: 90px; font-size: 35px"> </td> <td> <input type="button" value="6" id="6" onclick="onclicknum(6)" style="height: 70px; width: 90px; font-size: 35px"> </td> <td> <input type="button" value="-" id="sub" onclick="onclicknum('-')" style="height: 70px; width: 90px; font-size: 35px"> </td> </tr> <tr> <td> <input type="button" value="7" id="7" onclick="onclicknum(7)" style="height: 70px; width: 90px; font-size: 35px"> </td> <td> <input type="button" value="8" id="8" onclick="onclicknum(8)" style="height: 70px; width: 90px; font-size: 35px"> </td> <td> <input type="button" value="9" id="9" onclick="onclicknum(9)" style="height: 70px; width: 90px; font-size: 35px"> </td> <td> <input type="button" value="*" id="mul" onclick="onclicknum('*')" style="height: 70px; width: 90px; font-size: 35px"> </td> </tr> <tr> <td colspan="2"> <input type="button" value="0" id="0" onclick="onclicknum(0)" style="height: 70px; width: 190px; font-size: 35px"> </td> <td> <input type="button" value="." id="point" onclick="onclicknum('.')" style="height: 70px; width: 90px; font-size: 35px"> </td> <td> <input type="button" value="/" id="division" onclick="onclicknum('/')" style="height: 70px; width: 90px; font-size: 35px"> </td> </tr> <tr> <td colspan="2"> <input type="button" value="Del" id="clear" onclick="onclickclear()" style="height: 70px; width: 190px; font-size: 35px" /> </td> <td colspan="2"> <input type="button" value="=" id="result" onclick="onclickresult()" style="height: 70px; width: 190px; font-size: 35px" /> </td> </tr> </table> </body> </html>
效果圖
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:
- javascript寫的簡單的計(jì)算器,內(nèi)容很多,方法實(shí)用,推薦
- 簡易js代碼實(shí)現(xiàn)計(jì)算器操作
- js實(shí)現(xiàn)簡單計(jì)算器
- 用JS寫的簡單的計(jì)算器實(shí)現(xiàn)代碼
- javascript-簡單的計(jì)算器實(shí)現(xiàn)步驟分解(附圖)
- 網(wǎng)頁計(jì)算器 一個(gè)JS計(jì)算器
- 純javascript代碼實(shí)現(xiàn)計(jì)算器功能(三種方法)
- js網(wǎng)頁版計(jì)算器的簡單實(shí)現(xiàn)
- html+js實(shí)現(xiàn)簡單的計(jì)算器代碼(加減乘除)
- 基于JSP實(shí)現(xiàn)一個(gè)簡單計(jì)算器的方法
相關(guān)文章
深入淺析ES6 Class 中的 super 關(guān)鍵字
本文給大家收藏整理了ES6 Class 中的 super 關(guān)鍵字,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友參考下吧2017-10-10在標(biāo)題欄顯示新消息提示,很多公司項(xiàng)目中用到這個(gè)方法
在標(biāo)題欄顯示新消息提示,很多公司項(xiàng)目中用到這個(gè)方法,需要的朋友可以參考下。2011-11-11JavaScript-RegExp對象只能使用一次問題解決方法
RegExp對象執(zhí)行了一次后就廢掉了,所以每次用RegExp都需要重新new一個(gè),下面有個(gè)示例,需要的朋友可以參考下2014-06-06js canvas實(shí)現(xiàn)放大鏡查看圖片功能
這篇文章主要為大家詳細(xì)介紹了js canvas實(shí)現(xiàn)放大鏡查看圖片功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-06-06CSS+Js遮罩效果的TAB及焦點(diǎn)圖片切換(推薦)
CSS+Js圖片切換技術(shù),類似的已有不少了,這一個(gè)使用了遮罩過渡的效果,同樣應(yīng)用到了TAB選項(xiàng)卡上,本頁面僅是為了演示,大家用時(shí)候把它拆分開來,這個(gè)效果也對學(xué)習(xí)圖片效果制作很有幫助。2009-11-11