<html>
<head>
<title>js的计算器案例</title>
<meta charset="UTF-8"/>
<!--声明css代码域-->
<style type="text/css">
/*设置div样式*/
#showdiv{
border: solid 1px;
width: 300px;
height: 360px;
text-align: center;
border-radius: 10px;
margin: auto;
margin-top: 50px;
background-color: #EEE;
}
/*设置文本框样式*/
#data{
width: 270px;
height: 30px;
font-size: 15px;
margin-top: 20px;
margin-bottom: 20px;
}
/*设置按钮的样式*/
input[type=button]{
width: 55px;
height: 55px;
font-size: 25px;
margin: 5px;
background-color: #ccc;
}
</style>
<!--声明js代码域-->
<script type="text/javascript">
//声明计算器功能函数
function testMath(val){
//获取计算器文本框对象
var inp=document.getElementById("data");
//使用switch实现计算器的运算
switch (val){
case "=":
JS部分练习(书写计算器)
最新推荐文章于 2023-02-06 19:28:23 发布
本文介绍了使用JavaScript编写一个简单计算器的过程,涵盖了基本的数学运算和用户交互功能。通过学习,读者可以理解JavaScript在前端交互中的应用。
摘要由CSDN通过智能技术生成