【问题标题】:Javascript Addition calculatorJavascript 加法计算器
【发布时间】:2016-11-20 02:10:10
【问题描述】:

enter image description here

我如何在 html 中创建它。 当用户在文本框中输入值并单击添加按钮时,文本框变为空并且添加按钮被禁用。然后用户输入第二个值并单击在文本框中显示结果的 = 按钮。

【问题讨论】:

  • 欢迎来到 SO!请花点时间on this page 了解提问的内容和方法。
  • 到目前为止你尝试了什么?

标签: javascript html


【解决方案1】:

根据问题很难理解你到底想要什么,但是我已经为你准备了一个基本的小提琴,它应该可以解决你的问题或希望能给你和想法:

https://jsfiddle.net/Lzg5rfgr/

<table>
  <tr>
    <td>
      <input type="number" id="userNumber">
    </td>
  </tr>
  <tr>
    <td>
      <button id="plus">+</button>
    </td>
    <td>
      <span id="enteredNumber"></span>
    </td>
  </tr>
  <tr>
    <td>=</td>
    <td>
      <span id="result">0</span>
    </td>
  </tr>
</table>

使用 jquery 的javascript:

$("#plus").on('click', function(){
  var num = parseInt($("#userNumber").val()); // get the number
  $("#result").html(num + parseInt( $("#result").html()) );
  $("#userNumber").val(null); // empty the input box
  $("#enteredNumber").html(num);

})

【讨论】:

  • 我希望当用户在文本框中输入一个值并单击 + 按钮然后文本框变为空然后用户将从同一个文本框中输入第二个值并单击 = 按钮这将在文本框中显示结果。
猜你喜欢
  • 2013-10-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-09-13
相关资源
最近更新 更多