色综合图-色综合图片-色综合图片二区150p-色综合图区-玖玖国产精品视频-玖玖香蕉视频

您的位置:首頁技術(shù)文章
文章詳情頁

js實現(xiàn)網(wǎng)頁計算器

瀏覽:63日期:2024-03-25 09:10:18

如何在利用HTML,css和js的知識制作一個簡單的網(wǎng)頁計算器呢?

一個計算機(jī)中具備了:

計算機(jī)整體框 輸入框 輸入按鈕

計算機(jī)整體框:

/*設(shè)置div樣式*/ #showdiv{ border: solid 1px; border-radius: 5px; width: 350px; height: 400px; text-align: center; margin: auto;/*設(shè)置居中*/ margin-top: 50x; background-color: rgb(214, 219, 190); }

輸入框:

/*設(shè)置輸入框樣式*/ input[type=text]{ margin-top: 20px; width: 290px; height: 40px; font-size: 20px;}

輸入按鈕:

/*設(shè)置按鈕樣式*/ input[type=button]{ width: 60px; height: 60px; margin-top: 20px; margin-left: 5px; margin-right: 5px; font-size: 30px; font-weight: bolder; font-family: '楷書';}

使用js代碼對執(zhí)行對應(yīng)業(yè)務(wù)邏輯操作:

<!--聲明js代碼--><script> function test(btn){//獲取button按鈕對象var number = btn.value;//執(zhí)行對應(yīng)的業(yè)務(wù)邏輯switch (number) { case '=':document.getElementById('input').value= eval(document.getElementById('input').value);break; case 'c':document.getElementById('input').value='';break; default://將按鈕的值賦值給input輸入框document.getElementById('input').value+=number;break;} }</script>

使用HTML對計算機(jī)進(jìn)行排版布局:

<body> <div id='showdiv'><input type='text' readonly='readonly'><br><input type='button' value='1' onclick='test(this)'><input type='button' value='2' onclick='test(this)'><input type='button' value='3' onclick='test(this)'><input type='button' value='4' onclick='test(this)'><br><input type='button' value='5' onclick='test(this)'><input type='button' value='6' onclick='test(this)'><input type='button' value='7' onclick='test(this)'><input type='button' value='8' onclick='test(this)'><br><input type='button' value='9' onclick='test(this)'><input type='button' value='+' onclick='test(this)'><input type='button' value='-' onclick='test(this)'><input type='button' value='*' onclick='test(this)'><br><input type='button' value='0' onclick='test(this)'><input type='button' value='/' onclick='test(this)'><input type='button' value='c' onclick='test(this)'><input type='button' value='=' onclick='test(this)'> </div></body>

總體代碼:

<!DOCTYPE html><html lang='en'><head> <meta charset='UTF-8'> <meta http-equiv='X-UA-Compatible' content='IE=edge'> <meta name='viewport' content='width=device-width, initial-scale=1.0'> <style>/*設(shè)置div樣式*/#showdiv{ border: solid 1px; border-radius: 5px; width: 350px; height: 400px; text-align: center; margin: auto;/*設(shè)置居中*/ margin-top: 50x; background-color: rgb(214, 219, 190); }/*設(shè)置輸入框樣式*/input[type=text]{ margin-top: 20px; width: 290px; height: 40px; font-size: 20px;}/*設(shè)置按鈕樣式*/input[type=button]{ width: 60px; height: 60px; margin-top: 20px; margin-left: 5px; margin-right: 5px; font-size: 30px; font-weight: bolder; font-family: '楷書';}</style><!--聲明js代碼--><script> function test(btn){//獲取button按鈕對象var number = btn.value;//執(zhí)行對應(yīng)的業(yè)務(wù)邏輯switch (number) { case '=':document.getElementById('input').value= eval(document.getElementById('input').value);break; case 'c':document.getElementById('input').value='';break; default://將按鈕的值賦值給input輸入框document.getElementById('input').value+=number;break;} }</script> <title>Document</title></head><body> <div id='showdiv'><input type='text' readonly='readonly'><br><input type='button' value='1' onclick='test(this)'><input type='button' value='2' onclick='test(this)'><input type='button' value='3' onclick='test(this)'><input type='button' value='4' onclick='test(this)'><br><input type='button' value='5' onclick='test(this)'><input type='button' value='6' onclick='test(this)'><input type='button' value='7' onclick='test(this)'><input type='button' value='8' onclick='test(this)'><br><input type='button' value='9' onclick='test(this)'><input type='button' value='+' onclick='test(this)'><input type='button' value='-' onclick='test(this)'><input type='button' value='*' onclick='test(this)'><br><input type='button' value='0' onclick='test(this)'><input type='button' value='/' onclick='test(this)'><input type='button' value='c' onclick='test(this)'><input type='button' value='=' onclick='test(this)'> </div></body></html>

實現(xiàn)效果:

js實現(xiàn)網(wǎng)頁計算器

你一定已經(jīng)學(xué)會了前端網(wǎng)頁計算機(jī)的制作了吧!

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。

標(biāo)簽: JavaScript
相關(guān)文章:
主站蜘蛛池模板: 黄.www| 久久精品国产国产精品四凭 | 91欧美一区二区三区综合在线 | 亚洲天堂日韩在线 | 亚洲一区二区三区香蕉 | 精品免费国产一区二区三区 | 亚洲美女aⅴ久久久91 | 中国一级片免费看 | 欧美大片在线播放 | 97se亚洲综合在线韩国专区福利 | 久久久久久久99精品免费观看 | 在线成人播放毛片 | 国产亚洲欧美视频 | 黄色成人在线网站 | 久久久久亚洲香蕉网 | 97超级碰碰碰免费公开在线观看 | 手机在线观看一级午夜片 | 一级aaa毛片 | 伊人色综合久久天天人手人停 | 久草视频新 | 男人天堂成人 | 久国产精品视频 | 在线中文字幕亚洲 | 国产在线视频自拍 | 亚洲综合一区二区不卡 | 理论片中文字幕 | 特黄aaaaaa久久片 | 另类视频欧美 | 国产日韩欧美一区 | 国产毛片久久久久久国产毛片 | 日本综合欧美一区二区三区 | 不卡一区在线观看 | 性高湖久久久久久久久 | 成人毛片网站 | 激情性爽三级成人 | 亚洲欧洲日本天天堂在线观看 | 日本免费在线 | 激情6月丁香婷婷色综合 | 亚洲男人的天堂成人 | 欧美大片国产在线永久播放 | 亚洲成人午夜影院 |