3
4使用html+css+js实现简易计算器,
效果图如下:
html代码如下:
1 <!doctype html> 2 <html lang="en"> 3 <head> 4 <meta chart="utf-8"> 5 <meta name="viewport" content="width=device-width, initial-scale=1.0"> 6 <meta http-equiv="x-ua-compatible" content="ie=edge"> 7 <title>calculator</title> 8 <link rel="stylesheet" type="text/css" href="style.css"> 9 <script type="text/javascript" src="contain.js"></script>10 <title>document</title>11 </head>12 <body>13 <div class="calculator">14 <form name="calculator">15 <input type="text" id="display" value="">16 <br>17 <input type="button" class="btn number txt" value="tynam">18 <input type="button" id="clear" class="btn number" value="ac" onclick="cleardisplay();">19 <input type="button" class="btn number" value="<-" onclick="del();">20 <input type="button" class="btn operator" value="/" onclick="get(this.value);">21 <br>22 <input type="button" class="btn number" value="7" onclick="get(this.value);">23 <input type="button" class="btn number" value="8" onclick="get(this.value);">24 <input type="button" class="btn number" value="9" onclick="get(this.value);">25 <input type="button" class="btn operator" value="*" onclick="get(this.value);">26 <br>27 <input type="button" class="btn number" value="4" onclick="get(this.value);">28 <input type="button" class="btn number" value="5" onclick="get(this.value);">2林徽音9 <input type="button" class="btn number" value="6" onclick="get(this.value);">30 <input type="button" class="btn operator" value="+" onclick="get(this.value);">31 <br>32 <input type="button" class="btn number" value="1" onclick="get(this.value);">33 <input 世界名著读后感type="button" class="bt拉面王n number" value="2" onclick="get(this.value);">34 <input type="button" class="btn number" value="3" onclick="get(this.value);">35 <input type="button" class="btn operator" value="-" onclick="get(this.value);">36 <br>37 <input type="button" class="btn number" value="0" onclick="get(this.value);">38 <input type="button" class="btn number" value="." onclick="get(this.value);">39 <input type="button" class="btn operator equal" value="=" onclick="calculates();">40 </form>41 </div> 42 </body>43 </html>
css代码如下:
1 * { 2 border: none; 3 font-family: 'open sans', sans-rif; 4 margin: 0; 5 padding: 0; 6 } 7 8 .calculator { 9 background-color: #fff;10 height: 600px;11 margin: 50px auto;12 width: 600px;13 }14 15 form {16 background-color: rgb(75, 70, 71);17 padding: 5px 1px auto; 18 width: 245px;19 }20 .btn {21 outline: none;22 cursor: pointer;23 font-size: 20px;24 height: 45px;25 margin: 5px 0 5px 10px电脑光驱不读盘;26 width: 45px;27 28 }29 .btn:first-child {30 margin: 5px 0 5px 10px;31 }32 33 #display {34 outline: none;35 background-color: #dededc;36 color: rgb(75, 70, 71);37 font-size: 40px;38 height: 47px;39 text-align: right;40 width: 224px;41 margin: 10px 10px auto;42 }43 .number {44 background-color: rgb(143, 140, 140);45 color: #dededc;46 }47 48 .operator {49 background-color: rgb(239, 141, 49);50 color: #ffffff;51 }52 53 .equal{54 width: 105px;55 }56 57 .txt{58 font-size:12px;59 background: none;60 }
js代码如下:
/* display clear */ function cleardisplay() { document.getelementbyid("display").value = "";}/* del */function del() { var numb = ""; numb = document.getelementbyid("display").value; for(i=0;i<numb.length;i++) { document.getelementbyid("display").value = numb.substring(0,numb.length-1); if(numb == '')宝鸡文理学院专业 { document.getelementbyid("display").value = ''; } }} /* recebe os valores */function get(value) { document.getelementbyid("display").value += value; } /* calcula */function calculates() { var result = 0; result = document.getelementbyid("display").value; document.getelementbyid("display").value = ""; document.getelementbyid("display").value = eval(result);};
本文发布于:2023-04-03 13:23:42,感谢您对本站的认可!
本文链接:https://www.wtabcd.cn/fanwen/zuowen/96926def6e4ecf5fc686c14517ab8851.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文word下载地址:使用html+css+js实现简易计算器.doc
本文 PDF 下载地址:使用html+css+js实现简易计算器.pdf
留言与评论(共有 0 条评论) |