简体   繁体   English

我写了一个 function 来总结我在输入中输入的数字,但它没有用,为什么?

[英]I wrote a function that sums the numbers I entered in the inputs, but it didn't work, why?

sorry if it's silly.I want to add the numbers I entered in two separate inputs, but it doesn't work.抱歉,如果这很愚蠢。我想将我输入的数字添加到两个单独的输入中,但它不起作用。

  <body>


  <input type="number" id="number1"/>
  <input type="number" id="number2"/>
  <button onclick="plus()">Sum</button>
 

  <script>


  function plus (){
  let numberbox1 = document.getElementById("number1");
  let numberbox2 = document.getElementById("number2");
  let newnumber =  numberbox1 + numberbox2;
  
  
  let div = document.get.createElement("div");
  div.innerText = newnumber ;
  document.body.appendChild(div);
  }

  </script>

 let div = document.getElementById("num"); function plus (){ let numberbox1 = +document.getElementById("number1").value; let numberbox2 = +document.getElementById("number2").value; let newnumber = numberbox1 + numberbox2; console.log(newnumber) div.textContent = newnumber; }
 <input type="number" id="number1"/> <input type="number" id="number2"/> <button onclick="plus()">Sum</button> <div id="num"> </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我正在使用正则表达式功能,但它不起作用? - i am using regex function but it didn't work? 我尝试使用 .map function 但它对我的代码不起作用 - I tried to use the .map function but it didn't work on my code this.setState不是一个函数,为什么它不起作用? - this.setState is not a function why it didn't work? 我写了一个简单的粒子过滤器,它不能用于数百个以上的粒子。 我不知道为什么 - I wrote a simple particle filter and it won't work with more than a few hundred particles. I can't tell why 我写的这个函数怎么了? - What is wrong with this function I wrote? 为什么我的onclick功能没有起作用 - why my onclick function didn't work in react 为什么 function 不能与 else If 和 else 语句一起使用? - why the function didn't work with else If and works with else statment? 为什么我的编辑页面在 Laravel 中不起作用? 我用过 vue.js - Why my edit page didn't work in Laravel? I used vue.js 如果我向左推菜单中放置了4个以上的项目,为什么动画不起作用? - Why animation didn't work if I put more than 4 items in menu push left? 我正在尝试使用javascript ajax函数绑定数据库中的数据,但是它不起作用 - i'm trying to bind data from database using javascript ajax function but it didn't work
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM