Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

110
Views
Creación de calculadora basada en entrada HTML

Así que estoy tratando de crear una calculadora basada en entrada html, simplemente regresa * Este es un fragmento agregado más tarde, pero ¿Cómo haría esto en jQuery?

[objeto HTMLInputElement][objeto HTMLInputElement]

así que aquí está mi código

 <html> <head> </head> <body> <input id="nume" type="number"> <input id="num" type="number"> <input type="button" onclick="MyFunction()" value="Click to calculate"> <p id="f">Value Is: 0</p> </body> <script> const something = document.getElementById("nume") const somethingElse = document.getElementById("num") function MyFunction(){ var values = something + somethingElse; document.getElementById("f").innerHTML = "Value Is: " + values } </script>
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

necesitas obtener valor primero. document.getElementById("nume").value Puede hacerlo de esta manera

 function MyFunction(){ var values = Number(document.getElementById("nume").value) + Number(document.getElementById("num").value); document.getElementById("f").innerHTML = "Value Is: " + values }
 <html> <head> </head> <body> <input id="nume" type="number"> <input id="num" type="number"> <input type="button" onclick="MyFunction()" value="Click to calculate"> <p id="f">Value Is: 0</p> </body>

about 4 years ago · Juan Pablo Isaza Report

0

Debe usar Number(document.getElementById("nume").value) para obtener el número real. simplemente usando document.getElementById("nume") está obteniendo el elemento HTML DOM y no el valor del elemento.

about 4 years ago · Juan Pablo Isaza Report

0

  1. En primer lugar, su código tiene las dos variables que deberían estar dentro de la función.
  2. En segundo lugar, para acceder al atributo de valor de <input>
  3. en tercer lugar, obtuve el número como cadena, así que convertí la cadena de forma en número usando Number();
 <html> <head> </head> <body> <input id="nume" type="number"><br/> <input id="num" type="number"><br/> <input type="button" onclick="MyFunction()" value="Click to calculate"><br/> <p id="f">Value Is: 0</p> </body> <script> function MyFunction(){ var something=document.getElementById("nume").value; var somethingElse = document.getElementById("num").value; document.getElementById("f").innerHTML=Number(something)+Number(somethingElse); } </script>
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!