JS实现简易计算器实现简易计算器
用JS实现简易计算器,供大家参考,具体内容如下
首先创建结构和样式
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
body{
margin:0;
padding:0;
background-color: #abcdef;
}
.cal{
width:560px;
height:100px;
margin:0 auto;
padding-top:300px;
}
</style>
</head>
<body>
<div class="cal">
<p>
<input type="text" class="num1" value="1">
<span class="sign">+</span>
<input type="text" class="num2" value="1">
<span>=</span>
<span class="res">2</span>
</p>
<p>
<input type="button" value="+">
<input type="button" value="-">
<input type="button" value="*">
<input type="button" value="/">
</p>
</div>
<script>
</script>
</body>
</html>
然后添加Java script
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
body{
margin:0;
padding:0;
background-color: #abcdef;
}
.cal{
width:560px;
height:100px;
margin:0 auto;
padding-top:300px;
}
</style>
</head>
<body>