zoukankan      html  css  js  c++  java
  • js计算器案例

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>js计算器案例</title>
    <style type="text/css">
    #showdiv{
    border:solid 1px;
    300px;
    height: 400px;
    text-align: center;
    }
    input[type=text]{
    margin-top: 10px;
    290px;
    height: 40px;
    font-size:20px ;
    }
    input[type=button]{
    60px;
    height: 60px;
    margin-top: 20px;
    margin-left: 5px;
    margin-right: 5px;
    font-size: 30px;
    font-weight:bold ;
    }
    </style>
    <script type="text/javascript">
    function test(btn){
    var num=btn.value;
    switch(num){
    case "=":
    document.getElementById("inp").value=eval(document.getElementById("inp").value);
    break;
    case "c":
    document.getElementById("inp").value="";
    break;
    default:
    document.getElementById("inp").value=document.getElementById("inp").value+num;
    break;
    }
    }
    </script>
    </head>
    <body>
    <div id="showdiv">
    <input type="text" name="" id="inp" value="" readonly="readonly"/><br />
    <input type="button" name="" id="" value="1" onclick="test(this)"/>
    <input type="button" name="" id="" value="2" onclick="test(this)"/>
    <input type="button" name="" id="" value="3" onclick="test(this)"/>
    <input type="button" name="" id="" value="4" onclick="test(this)"/><br />
    <input type="button" name="" id="" value="5" onclick="test(this)"/>
    <input type="button" name="" id="" value="6" onclick="test(this)"/>
    <input type="button" name="" id="" value="7" onclick="test(this)"/>
    <input type="button" name="" id="" value="8" onclick="test(this)"/><br />
    <input type="button" name="" id="" value="9" onclick="test(this)"/>
    <input type="button" name="" id="" value="+" onclick="test(this)"/>
    <input type="button" name="" id="" value="-" onclick="test(this)"/>
    <input type="button" name="" id="" value="*" onclick="test(this)"/><br />
    <input type="button" name="" id="" value="0" onclick="test(this)"/>
    <input type="button" name="" id="" value="/" onclick="test(this)"/>
    <input type="button" name="" id="" value="c" onclick="test(this)"/>
    <input type="button" name="" id="" value="=" onclick="test(this)"/>


    </div>
    </body>
    </html>

  • 相关阅读:
    使用频率比较高的PHP函数方法
    penetration test:渗透测试
    penetration test:渗透测试
    按照数组的形式排序+条件切换切换查询
    PHP 性能优化技巧
    再谈PHP单引号和双引号区别
    表单验证的3个函数ISSET()、empty()、is_numeric()的使用方法
    向中级程序员转变必备的10个秘诀
    彻底杜绝PHP的session cookie错误
    Analysis by Its History_theorem 1.2
  • 原文地址:https://www.cnblogs.com/qhcyp/p/10617452.html
Copyright © 2011-2022 走看看