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

246
Views
¿Puedo agregar un evento al botón al hacer clic en tipo de entrada = búsqueda?

¿Hay algún evento disponible para hacer clic en el botón Borrar que solo aparece en el elemento de entrada de búsqueda html5?

Aquí está mi intento. Pero si uso "buscar", el evento también se activa al presionar enter.

es decir, si presiono enter, la consola imprime la búsqueda clara

 mySearchBar.addEventListener("keydown", (e) => { if (e.keyCode === ENTER_KEY_CODE) { console.log("search"); //Display search results } }); mySearchBar.addEventListener("search", () => { console.log("clear"); // Click the cross button of input type=search to Clear the search results and display all }); };
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Puede usar eventListener 'input' para verificar si la entrada está vacía cada vez que se agrega algo a la entrada, luego, si no hay valor, eso significa que la entrada de búsqueda se borró.

EDITAR: prueba de valor agregado en evento keydown

 mySearchBar = document.getElementById('search'); mySearchBar.addEventListener("keydown", (e) => { if (e.key === 'Enter') { if (!e.currentTarget.value) console.log('cleared'); else console.log("search"); } }); mySearchBar.addEventListener('input', (e) => { if (!e.currentTarget.value) console.log('cleared'); })
 <input type=search id=search>

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!