(简单记录)从零实现一个计算器,并制作成 APP,并实现网页模式

编程知识 更新时间:2023-04-25 16:34:31

二、练习内容

从零实现一个计算器,并制作成 APP,并实现网页模式

三、教程如下

1.软件 vscode、hbuilder

计算器 A 符号 B = result + - * / %

index.html

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>计算器</title>
    <link rel="stylesheet" href="global.css">
    <script src="calc.js" type="text/javascript"></script>
</head>

<body>
    <div class="calc">
        <!-- 输入框 -->
        <input type="text" id="inputA">
        <!-- 选择框 -->
        <select id="select">
            <option value="+">+</option>
            <option value="-">-</option>
            <option value="*">*</option>
            <option value="/">/</option>
            <option value="%">%</option>
        </select>
        <!-- 输入框 -->
        <input type="text" id="inputB">
        <!-- 计算按钮 -->
        <button id="btn" onclick="result()">计算</button>
        <!-- 结果 -->
        <input type="text" id="result">
    </div>
</body>

</html>

global.css

body,html{
    width: 100%;
    height: 100%;
}
.calc{
    display: flex;
    flex-direction: row;
    justify-content: center;
}

calc.js

function result() {
  var inputA = document.getElementById("inputA").value;
  var mysymbol = document.getElementById("select").value;
  var inputB = document.getElementById("inputB").value;

  if (mysymbol == "+") {
    document
      .getElementById("result")
      .setAttribute("value", parseInt(inputA) + parseInt(inputB));
  } else if (mysymbol == "-") {
    document
      .getElementById("result")
      .setAttribute("value", parseInt(inputA) - parseInt(inputB));
  } else if (mysymbol == "*") {
    console.log(parseInt(inputA));
    document
      .getElementById("result")
      .setAttribute("value", parseInt(inputA) * parseInt(inputB));
  } else if (mysymbol == "/") {
    document
      .getElementById("result")
      .setAttribute("value", parseFloat(inputA) / parseFloat(inputB));
  } else {
    document
      .getElementById("result")
      .setAttribute("value", parseFloat(inputA) % parseFloat(inputB));
  }
}

// 1  2  3
// 1.2  3.4  4.6

2.打包

2.1创建app项目

2.2复制文件html

2.3复制js和css +改地址

2.4设置app图标

2.5使用公有证书

2.6打包完成

3.结果

更多推荐

(简单记录)从零实现一个计算器,并制作成 APP,并实现网页模式

本文发布于:2023-04-19 10:24:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/60357ac92bdf7fdb7f33ba295eeb50fb.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:计算器   模式   简单   网页   APP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!

  • 87708文章数
  • 20321阅读数
  • 0评论数