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

254
Views
Cómo obtener el valor del botón pulsado en la calculadora

Tengo varios botones que contienen diferentes valores.

 <button data-action="digit" class="button" id="1">1</button> <button data-action="digit" class="button" id="2">2</button> <button data-action="digit" class="button" id="3">3</button>

Y quiero que estos botones se muestren en mi calculadora usando esto en javascript:

 function digit_pressed(digit) { console.log("digit pressed: " + digit); }

Pero no estoy seguro de qué agregar a mi función. Cualquier ayuda sería muy apreciada :)

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Puede usar querySelectorAll para seleccionar todo el button , luego use addEventListener para agregar un evento de clic y el último paso use textContent para el número de dígitos y la función de llamada.

 document.querySelectorAll('button').forEach(el =>{ el.addEventListener('click', () =>{ digit_pressed(el.textContent); }); }); function digit_pressed(digit) { console.log("digit pressed: " + digit); }
 <button data-action="digit" class="button" id="1">1</button> <button data-action="digit" class="button" id="2">2</button> <button data-action="digit" class="button" id="3">3</button>

Referencia:

  • querySelectorAll
  • agregarEventListener
  • contenido del texto
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!