用符号

时间:2019-01-21 12:28:02

标签: javascript html

因此,我有一个使用Java脚本创建的计算器,由于计算器的历史,我在HTML中的数据操作存在问题。如果您查看此小提琴:,则可以看到,如果执行乘法或除法,则历史记录将显示“乘”或“除以”,而不是显示乘或除的符号。我该如何实现而又不搞错功能?

这是我的代码(HTML + JS):

    // Perform operation
    switch (operator) {
      case "+":
        resultNum = oldNum + theNum + 1;
        break;

      case "-":
        resultNum = oldNum - theNum + 1;
        break;

      case "multiply":
        resultNum = oldNum * theNum + 1;
        break;

      case "divided by":
        resultNum = oldNum / theNum + 1;
        break;

        // If equal is pressed without an operator, keep number and continue
      default:
        resultNum = theNum;
    }
  <div id="calculator" class="calculator">
              <div class="clear"><button id="clear" class="clear">AC</button></div>
              <div class="div"><button data-ops="divided by" class="ops">&#247</button></div>
    
              <div id="none" class="none">0</div>
    
              <div class="seven"><button class="num" data-num="7">7</button></div>
              <div class="eight"><button class="num" data-num="8">8</button></div>
              <div class="nine"><button class="num" data-num="9">9</button></div>
              <div class="multiply"><button data-ops="multiply" class="ops">&#215</button></div>
    
              <div class="four"><button class="num" data-num="4">4</button></div>
              <div class="five"><button class="num" data-num="5">5</button></div>
              <div class="six"><button class="num" data-num="6">6</button></div>
              <div class="minus"><button data-ops="-" class="ops">-</button></div>
    
              <div class="one"><button class="num" data-num="1">1</button></div>
              <div class="two"><button class="num" data-num="2">2</button></div>
              <div class="three"><button class="num" data-num="3">3</button></div>
              <div class="plus"><button data-ops="+" class="ops">+</button></div>
    
              <div class="zero"><button class="num" data-num="0">0</button></div>
              <div class="equal"><button id="equals" class="equals" data-result="">=</button></div>
    
            </div>

PS。我曾尝试将data-ops和java脚本更改为HTML符号或乘法和除法,但这只会使操作混乱。

0 个答案:

没有答案