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>

  • 相关阅读:
    MongoDB for OPS 02:复制集 RS 配置
    MongoDB for OPS 01:服务介绍与基本使用
    Redis for OPS 07:Redis 补充说明
    Redis for OPS 06:Redis Cluster 集群
    google ctemplate——c++模板引擎
    libctemplate——源码分析
    使用gulp对js、css、img进行合并压缩
    Windows平台交叉编译Arm Linux平台的QT5.7库
    使用gtest对DLL工程进行单元测试的实践
    websocket++简单使用例子
  • 原文地址:https://www.cnblogs.com/apolloren/p/7624516.html
Copyright © 2011-2022 走看看