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>

  • 相关阅读:
    vue获取下拉框值
    vue子父组件通信
    内存堆栈问题
    Object.defineProperty()--数据劫持原理
    call和apply和bind的区别
    Object.create()和new object()和{}的区别
    Object.keys()/Object.values()的简单理解
    object.assign
    泛型的定义、使用
    ts 泛型
  • 原文地址:https://www.cnblogs.com/qhcyp/p/10617452.html
Copyright © 2011-2022 走看看