简单计算器

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style type="text/css">
.zy{
height: 170px;
width: 300px;
margin: 0px auto;


/* border:1px #222222 solid;*/
}
.zy1{
height: 15px;
width: 275px;
margin-top: 15px;
}
.fk{
height: 15px;
width: 75px;
float: left;
}
.fk1{
height: 15px;
width: 200px;
float: left;
}
.fk2{
height: 15px;
width: 275px;
float: left;
}
p{
alige="senter";
}
</style>
<script type="text/javascript">
    function fuhao(yunsuan){
      var one=document.getElementById("first");
      var two=document.getElementById("second");
      var three=document.getElementById("third");
     if(yunsuan=="jia"){
      three.value=Number(one.value)+Number(two.value);
     }else if(yunsuan=="jian"){
      three.value=Number(one.value)-Number(two.value);
     }else if(yunsuan=="cheng"){
      three.value=Number(one.value)*Number(two.value);
     }else if(yunsuan=="chu"){
      three.value=Number(one.value)/Number(two.value);
     }
     }
</script>
</head>
<body>


<div class="zy">
<div><p align="center">计算机</p></div>


<div class="zy1">
   <div class="fk">
        第一个数
   </div>
   <div class="fk1">
       <input type="text"  id="first">   
       <input type="submit"  value="+" id="jia" onclick="fuhao(this.id)"
   </div>
</div>
<hr>
<div class="zy1">
    <div class="fk">
        第二个数
    </div>
    <div class="fk1">
        <input type="text"  id="second">   
        <input type="submit"  value="-" id="jian" onclick="fuhao(this.id)">
    </div>
</div>
<hr>
<div class="zy1">
    <div class="fk">
           结果
    </div>
    <div class="fk1">
       <input type="text"  id="third">  
       <input type="submit"  value="*" id="cheng" onclick="fuhao(this.id)">       
    </div>
</div>
<hr>
<div class="zy1">
    <div class="fk2">
       运算方法:先两个数再选择算法 
       <input type="submit"  value="/" id="chu" onclick="fuhao(this.id)">
    </div>
</div>
<hr>
</div>
</body>
</html>
阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭