麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 編程 > JavaScript > 正文

javascript實(shí)現(xiàn)簡單計(jì)算器效果【推薦】

2019-11-20 10:14:30
字體:
供稿:網(wǎng)友

最終效果如下圖-2,有bug:就是整數(shù)后點(diǎn)擊%號結(jié)果正確,如果小數(shù)后面點(diǎn)擊%的話結(jié)果就錯(cuò)誤!其他都正常,求指點(diǎn):input的value是string類型的,在JS中改如何正確處理下圖-1中的if部分??

圖-1

圖-2

HTML代碼如下

<body><div id="calculator">  <div class="LOGO">    <span class="name">簡單的計(jì)算器</span>    <span class="verson">@walker</span>  </div>  <div id="shuRu">    <!--screen輸入欄-->    <div class="screen">      <input type="text" id="screenName" name="screenName" class="screen">    </div>  </div>  <div id="keys">    <!-- j -->    <!--第一排-->    <input type="button" id="7" onclick="jsq(this.id)" value="7" class="buttons">    <input type="button" id="8" onclick="jsq(this.id)" value="8" class="buttons">    <input type="button" id="9" onclick="jsq(this.id)" value="9" class="buttons">    <input type="button" id="Back" onclick="tuiGe()" value="Back" class="buttons">    <input type="button" id="C" onclick="clearNum()" value="C" class="buttons" style="margin-right:0px">    <!--第二排-->    <input type="button" id="4" onclick="jsq(this.id)" value="4" class="buttons">    <input type="button" id="5" onclick="jsq(this.id)" value="5" class="buttons">    <input type="button" id="6" onclick="jsq(this.id)" value="6" class="buttons">    <input type="button" id="*" onclick="jsq(this.id)" value="X" class="buttons">    <input type="button" id="/" onclick="jsq(this.id)" value="/" class="buttons" style="margin-right:0px">    <!--第三排-->    <input type="button" id="1" onclick="jsq(this.id)" value="1" class="buttons">    <input type="button" id="2" onclick="jsq(this.id)" value="2" class="buttons">    <input type="button" id="3" onclick="jsq(this.id)" value="3" class="buttons">    <input type="button" id="+" onclick="jsq(this.id)" value="+" class="buttons">    <input type="button" id="-" onclick="jsq(this.id)" value="-" class="buttons" style="margin-right:0px">    <!--第四排-->    <input type="button" id="0" onclick="jsq(this.id)" value="0" class="buttons">    <input type="button" id="00" onclick="jsq(this.id)" value="00" class="buttons">    <input type="button" id="." onclick="jsq(this.id)" value="." class="buttons">    <input type="button" id="%" onclick="jsq(this.id)" value="%" class="buttons">    <input type="button" id="eva" onclick="eva()" value="=" class="buttons" style="margin-right:0px">  </div>  <div class="footer">    <span class="aside">歡迎使用JavaScript計(jì)算器</span>      <span class="link">        <a href="#" title="聲明" target="_blank">反饋</a>      </span>  </div></div></body>

CSS代碼如下:

<style>    /*Basic reset*/*{  margin:0;  padding:0;  box-sizing: border-box;  font: 14px Arial,sans-serif;}html{  height:100%;  background-color:lightslategrey;}#calculator{  margin: 15px auto;  width:330px;  height:400px;  border: 1px solid lightgray;  background-color:darkgrey;  padding:15px;}/*LOGO*/.LOGO{  height:20px;}.LOGO .name{  float:left;  line-height:30px;}.LOGO .verson{  float:right;  line-height:30px;}/*screen*/#shuRu{  margin-top:15px;}.screen{  margin-top:5px;  width:300px;  height:40px;  text-align: right;  padding-right:10px;  font-size:20px;}#keys{  border:1px solid lightgray;  height:223px;  margin-top:25px;  padding:8px;}#keys .last{  margin-right:0px;}.footer{  margin-top:20px;  height:20px;}.footer .link{  float:right;}#keys .buttons{  float:left;  width: 42px;  height: 36px;  text-align:center;  background-color:lightgray;  margin: 0 17px 20px 0;}  </style>

javascript代碼如下:

<script>     var num = 0; // 定義第一個(gè)輸入的數(shù)據(jù)     function jsq(num) {       //獲取當(dāng)前輸入       if(num=="%"){         document.getElementById('screenName').value=Math.round(document.getElementById('screenName').value)/100;       }else{         document.getElementById('screenName').value += document.getElementById(num).value;       }     }     function eva() {       //計(jì)算輸入結(jié)果       document.getElementById("screenName").value = eval(document.getElementById("screenName").value);     }     function clearNum() {       //清0       document.getElementById("screenName").value = null;       document.getElementById("screenName").focus();     }     function tuiGe() {       //退格       var arr = document.getElementById("screenName");       arr.value = arr.value.substring(0, arr.value.length - 1);     }   </script> 

以上這篇javascript實(shí)現(xiàn)簡單計(jì)算器效果【推薦】就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持武林網(wǎng)。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 精品一区二区三区免费毛片 | 成人h精品动漫一区二区三区 | 成人免费电影在线观看 | 日本黄色免费播放 | 爱逼爱操综合网 | 欧美激情精品久久久久久黑人 | 国产午夜电影 | 深夜毛片免费看 | 成年免费在线视频 | 狠狠干视频网站 | 成人午夜精品 | 人禽l交免费视频观看 视频 | 3344永久免费| 色播视频在线播放 | 国产亚洲高清在线精品不卡 | xx53xx| 亚洲片在线 | 国产九色视频在线观看 | 欧美扩阴视频 | 九九精品在线观看 | 国产精品aⅴ | 色网站综合 | 欧美人成在线 | 亚洲看片网 | 免费嗨片首页中文字幕 | chinese xvideos gay| 国产永久免费观看 | 久久久一区二区三区视频 | 99久久精品免费 | 免费看a级片 | 中文字幕在线网 | 鲁丝一区二区二区四区 | 久久久久中精品中文字幕19 | 在线天堂中文字幕 | 欧美综合日韩 | 91久久久久久| 精品国产一区二区亚洲人成毛片 | 久草视频手机在线观看 | 国产精品欧美久久久久一区二区 | 中文字幕综合在线观看 | 国产精品爱久久久久久久 |