javascript开发之计算器前端
计算器再页面展示上的内容很简单,就是数字和运算符号。下面展示出代码供讲解和参考:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta name="format-detection" content="telephone=no" />
<title>计算器</title>
<style type="text/css">
*{margin:0;padding:0;}
body{
background:#ffffcc;
font-size:12px;
font-family:"微软雅黑";
color:#666;
}
ul,ol{list-style:none;}
.cac{
width:830px;
background:#399;
margin:0 auto;
}
.cac .c_title{
font-size:16px;
color:#000;
padding:10px 0 10px 10px;
cursor:move;
}
.cac .c_show .c_txt{
width:800px;
height:42px;
font-size:34px;
color:#999;
border:none;
outline:none;
text-align:right;
padding-right:20px;
line-height:42px;
}
.cac .c_key ul{
border:1px solid #fff
}
.cac .c_key ul li{
border:1px solid #fff;
width:140px;
height:65px;
font-size:32px;
margin:10px;
float:left;
background:#cccc33;
line-height:65px;
cursor:pointer;
text-align:center;
}
.cac .c_key .c_tool{
background:#3399cc;
}
.clear{clear:both;}
</style>
</head>
<body>
<div>
<div>计算器</div>
<div>
<input type="text" value="0" onfocus="this.blur();" id="result"/> //onfocus="this.blur();"作用是使键盘无法输入
</div>
<div>
<ul>
<li onclick="command(7);">7</li> //每个按钮都要添加onclick点击事件,不然按钮不能用;
<li onclick="command(8);">8</li>
<li onclick="command(9);">9</li>
<li><-</li>
<li onclick="clearzero('j');">C</li>
<li onclick="command(4);">4</li>
<li onclick="command(5);">5</li>
<li onclick="command(6);">6</li>
<li onclick="tools('*','g');">×</li>
<li onclick="tools('/','g');">÷</li>
<li onclick="command(1);">1</li>
<li onclick="command(2);">2</li>
<li onclick="command(3);">3</li>
<li onclick="tools('+','g');">+</li>
<li onclick="tools('-','g');">-</li>
<li onclick="command(0);">0</li>
<li onclick="command(00);">00</li>
<li onclick="dot('g');">.</li>
<li onclick="tools('%','g');">%</li>
<li onclick="equal('j');">=</li>
<div></div>
</ul>
</div>
</div>
</body>
</html>这是HTML和CSS的代码。
前端的写法其实很简单,学习完HTML+CSS之后是可以做出来的。
neue Datei
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta name="format-detection" content="telephone=no" />
<title>计算器</title>
<style type="text/css">
*{margin:0;padding:0;}
body{
background:#ffffcc;
font-size:12px;
font-family:"微软雅黑";
color:#666;
}
ul,ol{list-style:none;}
.cac{
width:830px;
background:#399;
margin:0 auto;
}
.cac .c_title{
font-size:16px;
color:#000;
padding:10px 0 10px 10px;
cursor:move;
}
.cac .c_show .c_txt{
width:800px;
height:42px;
font-size:34px;
color:#999;
border:none;
outline:none;
text-align:right;
padding-right:20px;
line-height:42px;
}
.cac .c_key ul{
border:1px solid #fff
}
.cac .c_key ul li{
border:1px solid #fff;
width:140px;
height:65px;
font-size:32px;
margin:10px;
float:left;
background:#cccc33;
line-height:65px;
cursor:pointer;
text-align:center;
}
.cac .c_key .c_tool{
background:#3399cc;
}
.clear{clear:both;}
</style>
</head>
<body>
<div>
<div>计算器</div>
<div>
<input type="text" value="0" onfocus="this.blur();" id="result"/> //onfocus="this.blur();"作用是使键盘无法输入
</div>
<div>
<ul>
<li onclick="command(7);">7</li> //每个按钮都要添加onclick点击事件,不然按钮不能用;
<li onclick="command(8);">8</li>
<li onclick="command(9);">9</li>
<li><-</li>
<li onclick="clearzero('j');">C</li>
<li onclick="command(4);">4</li>
<li onclick="command(5);">5</li>
<li onclick="command(6);">6</li>
<li onclick="tools('*','g');">×</li>
<li onclick="tools('/','g');">÷</li>
<li onclick="command(1);">1</li>
<li onclick="command(2);">2</li>
<li onclick="command(3);">3</li>
<li onclick="tools('+','g');">+</li>
<li onclick="tools('-','g');">-</li>
<li onclick="command(0);">0</li>
<li onclick="command(00);">00</li>
<li onclick="dot('g');">.</li>
<li onclick="tools('%','g');">%</li>
<li onclick="equal('j');">=</li>
<div></div>
</ul>
</div>
</div>
</body>
</html>
Vorschau
Clear
- Kursempfehlungen
- Kursunterlagen herunterladen
Die Kursunterlagen stehen derzeit nicht zum Download zur Verfügung. Die Mitarbeiter organisieren es derzeit. Bitte schenken Sie diesem Kurs in Zukunft mehr Aufmerksamkeit
Auch Studierende, die diesen Kurs gesehen haben, lernen
Lassen Sie uns kurz über die Gründung eines Unternehmens in PHP sprechen
Kurze Einführung in die Web-Frontend-Entwicklung
Umfangreiche, praktische Tianlongbabu-Entwicklung eines Mini-Version-MVC-Frameworks, das die Enzyklopädie-Website mit peinlichen Dingen imitiert
Erste Schritte mit der praktischen PHP-Entwicklung: Schnelle PHP-Erstellung [Small Business Forum]
Anmeldebestätigung und klassisches Message Board
Wissenssammlung über Computernetzwerke
Schnellstart-Node.JS-Vollversion
Der Frontend-Kurs, der Sie am besten versteht: HTML5/CSS3/ES6/NPM/Vue/...[Original]
Schreiben Sie Ihr eigenes PHP-MVC-Framework (40 Kapitel ausführlich/große Details/Muss gelesen werden, damit Neulinge vorankommen)
















