如何用HTML CSS JS编写一个长尾词搜索功能的简易计算器?

2026-04-05 11:338阅读0评论SEO资讯
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计735个文字,预计阅读时间需要3分钟。

如何用HTML CSS JS编写一个长尾词搜索功能的简易计算器?

使用HTML、CSS和JavaScript实现简易计算器,效果如图所示:

HTML代码: 简易计算器 body { display: flex; justify-content: center; align-items: center; height: 100vh; background-color: #f0f0f0; } .calculator { border: 1px solid #ccc; padding: 20px; background-color: #fff; border-radius: 5px; } .display { width: 100%; margin-bottom: 10px; text-align: right; font-size: 24px; } .button { width: 20%; padding: 10px; margin: 5px; border: none; background-color: #007BFF; color: white; border-radius: 5px; cursor: pointer; } 0

使用html+css+js实现简易计算器,

效果图如下:

如何用HTML CSS JS编写一个长尾词搜索功能的简易计算器?

html代码如下

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>calculator</title> <link rel="stylesheet" type="text/css" href="style.css" rel="external nofollow" > <script type="text/javascript" src="contain.js"></script> <title>Document</title> </head> <body> <div class="calculator"> <form name="calculator"> <input type="text" id="display" value=""> <br> <input type="button" class="btn number txt" value="TYNAM"> <input type="button" id="clear" class="btn number" value="AC" onclick="cleardisplay();"> <input type="button" class="btn number" value="<-" onclick="del();"> <input type="button" class="btn operator" value="/" onclick="get(this.value);"> <br> <input type="button" class="btn number" value="7" onclick="get(this.value);"> <input type="button" class="btn number" value="8" onclick="get(this.value);"> <input type="button" class="btn number" value="9" onclick="get(this.value);"> <input type="button" class="btn operator" value="*" onclick="get(this.value);"> <br> <input type="button" class="btn number" value="4" onclick="get(this.value);"> <input type="button" class="btn number" value="5" onclick="get(this.value);"> <input type="button" class="btn number" value="6" onclick="get(this.value);"> <input type="button" class="btn operator" value="+" onclick="get(this.value);"> <br> <input type="button" class="btn number" value="1" onclick="get(this.value);"> <input type="button" class="btn number" value="2" onclick="get(this.value);"> <input type="button" class="btn number" value="3" onclick="get(this.value);"> <input type="button" class="btn operator" value="-" onclick="get(this.value);"> <br> <input type="button" class="btn number" value="0" onclick="get(this.value);"> <input type="button" class="btn number" value="." onclick="get(this.value);"> <input type="button" class="btn operator equal" value="=" onclick="calculates();"> </form> </div> </body> </html>

CSS代码如下:

* { border: none; font-family: 'Open Sans', sans-serif; margin: 0; padding: 0; } .calculator { background-color: #fff; height: 600px; margin: 50px auto; width: 600px; } form { background-color: rgb(75, 70, 71); padding: 5px 1px auto; width: 245px; } .btn { outline: none; cursor: pointer; font-size: 20px; height: 45px; margin: 5px 0 5px 10px; width: 45px; } .btn:first-child { margin: 5px 0 5px 10px; } #display { outline: none; background-color: #dededc; color: rgb(75, 70, 71); font-size: 40px; height: 47px; text-align: right; width: 224px; margin: 10px 10px auto; } .number { background-color: rgb(143, 140, 140); color: #dededc; } .operator { background-color: rgb(239, 141, 49); color: #ffffff; } .equal{ width: 105px; } .txt{ font-size:12px; background: none; }

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); };

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持易盾网络。

本文共计735个文字,预计阅读时间需要3分钟。

如何用HTML CSS JS编写一个长尾词搜索功能的简易计算器?

使用HTML、CSS和JavaScript实现简易计算器,效果如图所示:

HTML代码: 简易计算器 body { display: flex; justify-content: center; align-items: center; height: 100vh; background-color: #f0f0f0; } .calculator { border: 1px solid #ccc; padding: 20px; background-color: #fff; border-radius: 5px; } .display { width: 100%; margin-bottom: 10px; text-align: right; font-size: 24px; } .button { width: 20%; padding: 10px; margin: 5px; border: none; background-color: #007BFF; color: white; border-radius: 5px; cursor: pointer; } 0

使用html+css+js实现简易计算器,

效果图如下:

如何用HTML CSS JS编写一个长尾词搜索功能的简易计算器?

html代码如下

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>calculator</title> <link rel="stylesheet" type="text/css" href="style.css" rel="external nofollow" > <script type="text/javascript" src="contain.js"></script> <title>Document</title> </head> <body> <div class="calculator"> <form name="calculator"> <input type="text" id="display" value=""> <br> <input type="button" class="btn number txt" value="TYNAM"> <input type="button" id="clear" class="btn number" value="AC" onclick="cleardisplay();"> <input type="button" class="btn number" value="<-" onclick="del();"> <input type="button" class="btn operator" value="/" onclick="get(this.value);"> <br> <input type="button" class="btn number" value="7" onclick="get(this.value);"> <input type="button" class="btn number" value="8" onclick="get(this.value);"> <input type="button" class="btn number" value="9" onclick="get(this.value);"> <input type="button" class="btn operator" value="*" onclick="get(this.value);"> <br> <input type="button" class="btn number" value="4" onclick="get(this.value);"> <input type="button" class="btn number" value="5" onclick="get(this.value);"> <input type="button" class="btn number" value="6" onclick="get(this.value);"> <input type="button" class="btn operator" value="+" onclick="get(this.value);"> <br> <input type="button" class="btn number" value="1" onclick="get(this.value);"> <input type="button" class="btn number" value="2" onclick="get(this.value);"> <input type="button" class="btn number" value="3" onclick="get(this.value);"> <input type="button" class="btn operator" value="-" onclick="get(this.value);"> <br> <input type="button" class="btn number" value="0" onclick="get(this.value);"> <input type="button" class="btn number" value="." onclick="get(this.value);"> <input type="button" class="btn operator equal" value="=" onclick="calculates();"> </form> </div> </body> </html>

CSS代码如下:

* { border: none; font-family: 'Open Sans', sans-serif; margin: 0; padding: 0; } .calculator { background-color: #fff; height: 600px; margin: 50px auto; width: 600px; } form { background-color: rgb(75, 70, 71); padding: 5px 1px auto; width: 245px; } .btn { outline: none; cursor: pointer; font-size: 20px; height: 45px; margin: 5px 0 5px 10px; width: 45px; } .btn:first-child { margin: 5px 0 5px 10px; } #display { outline: none; background-color: #dededc; color: rgb(75, 70, 71); font-size: 40px; height: 47px; text-align: right; width: 224px; margin: 10px 10px auto; } .number { background-color: rgb(143, 140, 140); color: #dededc; } .operator { background-color: rgb(239, 141, 49); color: #ffffff; } .equal{ width: 105px; } .txt{ font-size:12px; background: none; }

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); };

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持易盾网络。