亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

您的位置:首頁技術文章
文章詳情頁

js實現網頁計算器

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

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

一個計算機中具備了:

計算機整體框 輸入框 輸入按鈕

計算機整體框:

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

輸入框:

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

輸入按鈕:

/*設置按鈕樣式*/ 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代碼對執行對應業務邏輯操作:

<!--聲明js代碼--><script> function test(btn){//獲取button按鈕對象var number = btn.value;//執行對應的業務邏輯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對計算機進行排版布局:

<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>/*設置div樣式*/#showdiv{ border: solid 1px; border-radius: 5px; width: 350px; height: 400px; text-align: center; margin: auto;/*設置居中*/ margin-top: 50x; background-color: rgb(214, 219, 190); }/*設置輸入框樣式*/input[type=text]{ margin-top: 20px; width: 290px; height: 40px; font-size: 20px;}/*設置按鈕樣式*/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;//執行對應的業務邏輯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>

實現效果:

js實現網頁計算器

你一定已經學會了前端網頁計算機的制作了吧!

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: JavaScript
相關文章:
主站蜘蛛池模板: 成人中文字幕一区二区三区 | 国产99久9在线视频 国产99久久精品 | 国产在线播放拍拍拍 | 成人18免费网站在线观看 | 欧美一级特黄aa大片 | 91成人午夜性a一级毛片 | 婷婷综合五月 | 国产夜趣福利免费视频 | 国产chinese在线视频 | 亚a在线| 国产美女亚洲精品久久久毛片 | 激情五月色综合婷婷大片 | 精品国产日韩久久亚洲 | 丁香婷婷色综合亚洲小说 | 一级黄色国产片 | 亚洲美女在线播放 | 欧美系列在线播放 | 看真人视频a级毛片 | 国产一级真人毛爱做毛片 | 黄色在线免费观看 | 亚洲一区二区三区不卡在线播放 | 国产中文字幕亚洲 | 欧美久在线观看在线观看 | 欧美久久伊人 | 国产在线色视频 | 看黄视频在线观看 | 在线视频不卡国产在线视频不卡 | 日韩免费精品一级毛片 | 大学生一级特黄的免费大片视频 | 国产精品久久久久久久成人午夜 | 国产精品亚洲片在线观看麻豆 | 一级h片 | 亚洲第一视频 | 欧美视频一二三区 | 在线欧美一级毛片免费观看 | 免费国产成人α片 | 久久本道久久综合伊人 | 亚洲午夜电影一区二区三区 | 国产精品一区久久精品 | 国产大片好看免费播放 | 久久aaa |