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

130
Views
La secuencia de comandos no funciona cuando el evento se cambia de "pasar el mouse" a "hacer clic"

El siguiente script no funciona cuando cambio el evento a "hacer clic" en lugar de "pasar el mouse". ¿Alguna idea de por qué? Lo que quiero decir con no funciona es que no puedo PUBLICAR ningún dato JSON en el servicio de almacenamiento JSON.

 <script> const button = document.getElementById("search-image") const s = document.getElementById("s") function SendData(){ var xhr = new XMLHttpRequest(); var url = "https://krat.es/xxxxx"; xhr.open("POST", url, true); xhr.setRequestHeader("Content-Type", "application/json"); xhr.onreadystatechange = function () { if (xhr.readyState === 4 && xhr.status === 200) { var json = JSON.parse(xhr.responseText); } }; var data = JSON.stringify({"Text": s.value}); console.log(data) xhr.send(data); } button.addEventListener("mouseover",SendData) </script>

Actualización: código HTML

 <form _lpchecked="1" action="/search" class="search-form" id="searchform" method="get"> <fieldset> <input id="s" name="q" onfocus="if(this.value=='Search')this.value='';" onwebkitspeechchange="transcribe(this.value)" type="text" value="Search" x-webkit-speech=""> <button class="sbutton" id="search-image" style="border:0; vertical-align: top;background: transparent;"><i class="fa fa-search"></i></button> </fieldset> </form>
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Puede reemplazar el mouseover con un clic y debe escribir el texto en el área de búsqueda e ingresar, podrá obtener la respuesta

 button.addEventListener("click",SendData)

consulte el siguiente enlace para obtener el código completo

about 4 years ago · Juan Pablo Isaza Report

0

Tu botón está dentro de un formulario. Entonces, cuando haga clic en el botón del formulario, se enviará y no permitirá que se ejecute su código JavaScript.
Así que cambia el código del botón de esta manera

html:

 /* type="button" */ <button type="button" class="sbutton" id="search-image" style="border:0; vertical-align: top;background: transparent;"><i class="fa fa-search"></i></button>

js:

 button.addEventListener("click",SendData)
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!