zoukankan      html  css  js  c++  java
  • js实现两个文本框数值的加减乘除运算

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <title></title>
    <script type="text/javascript">
    function count(){
    var a = parseInt(document.getElementById("tex1").value);
    var b = parseInt(document.getElementById("tex2").value);
    var selectSign = document.getElementById("select").value;

    switch (selectSign)
    {
    case '+': answer = a+b;break;
    case '-': answer = a-b;break;
    case '*': answer = a*b;break;
    case '/': answer = a/b;
    }
    document.getElementById("fruit").value = answer;
    }
    </script>
    </head>
    <body>
    <input type="text" id="tex1" />
    <select id="select">
    <option value="+">+</option>
    <option value="-">-</option>
    <option value="*">*</option>
    <option value="/">/</option>
    </select>
    <input type="text" id="tex2" />
    <input type="button" value=" = " onclick="count()" />
    <input type="text" id="fruit" onclick="count()" />
    </body>
    </html>

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <title></title>
    <script type="text/javascript">
    function count(){
    var a = parseInt(document.getElementById("tex1").value);
    var b = parseInt(document.getElementById("tex2").value);
    var selectSign = document.getElementById("select").value;

    switch (selectSign)
    {
    case '+': answer = a+b;break;
    case '-': answer = a-b;break;
    case '*': answer = a*b;break;
    case '/': answer = a/b;
    }
    document.getElementById("fruit").value = answer;
    }
    </script>
    </head>
    <body>
    <input type="text" id="tex1" />
    <select id="select">
    <option value="+">+</option>
    <option value="-">-</option>
    <option value="*">*</option>
    <option value="/">/</option>
    </select>
    <input type="text" id="tex2" />
    <input type="button" value=" = " onclick="count()" />
    <input type="text" id="fruit" onclick="count()" />
    </body>
    </html>

  • 相关阅读:
    css
    AcWing 145 超市 (贪心)
    AcWing 144 最长异或值路径 (Trie)
    AcWing 143 最大异或对 (Trie)
    AcWing 142 前缀统计 (Trie)
    AcWing 141 周期 (KMP)
    AcWing 139 回文子串的最大长度 (哈希+二分 / Manacher)
    AcWing 136 邻值查找 (set)
    AcWing 133 蚯蚓 (队列)
    AcWing 131 直方图中最大的矩形 (单调栈)
  • 原文地址:https://www.cnblogs.com/apolloren/p/7624516.html
Copyright © 2011-2022 走看看