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

108
Views
Alternar un booleano con dos botones

Hay 3 booleanos: a, b y c.

a y b son como botones. Normalmente son falsos. Solo cuando se activan son verdaderas. Como un impulso.

Cuando activé la a, la c debería ser verdadera y debería mantener el estado hasta que se active la b. Después de activar b, la c debería pasar a falso, manteniendo el estado hasta que a se active de nuevo.

Quiero escribirlo en JavaScript. Lo necesito para que el software hmi controle los botones reales. Gracias.

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

0

Puede utilizar operadores ternarios ( ?: ) y negación ( ! ):

 let A = false, B = false, C = false, a = document.getElementById('a'), b = document.getElementById('b'), c = document.getElementById('c'); function changeC(clickedBtn) { if(clickedBtn === 'a') { a.innerHTML = A === false ? true : false; A = !A; } else if(clickedBtn === 'b') { b.innerHTML = B === false ? true : false; B = !B; } c.innerHTML = C === false ? true : false; C = !C; }
 <button id="a" onclick="changeC('a')"> false </button> <button id="b" onclick="changeC('b')"> false </button> <button id="c"> false </button>

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!