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

205
Views
El cuadro de entrada alerta el texto haciendo clic en un botón (realmente nuevo en JQuery)

Parte JQuery

Acabo de empezar a usar JQuery. Primero quería crear un cuadro de entrada con un botón que alertara el texto que está en ese cuadro. Esta es la forma en que quería hacer eso.

 $(document).ready(function() { $('#hit').click(function() { alert($('#term').val()); }); });

Ese es el código en la parte del cuerpo html. Aquí no estoy seguro si tengo que declarar la identificación con un # o no. Intenté ambos pero no funcionó para ambos.

Mi código

 <!DOCTYPE html> <html> <head> <title>Button Event</title> <script src="cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"> $(document).ready(function() { $('#hit').click(function() { alert($('#term').val()); }); }); </script> </head> <body> <input id="term" type="text" value="enter your search"> <button id="hit" type="button" name="Button">Search</button> </body> </html>

Soy realmente nuevo en JavaScript y Jquery. Cuando ejecuto este código, no hay errores ni nada por el estilo en la consola, simplemente en blanco. El botón y el campo de entrada están en el sitio web, pero cuando ingreso algo y hago clic en el botón después de eso, no sucede nada. Por eso estoy seguro de que hay algunos errores en ese código.

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

0

 $(document).ready(function() { $('#hit').click(function() { alert($('#term').val()); }); });
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <input id="term" type="text" value="enter your search" /> <button id="hit" type="button" name="Button">Search</button>

aquí ha funcionado, ¿ha importado una biblioteca jquery?

Resolución con tu código:

 <!DOCTYPE html> <html> <head> <title>Button Event</title> </head> <body> <input id="term" type="text" value="enter your search"> <button id="hit" type="button" name="Button">Search</button> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script> $(document).ready(function() { $('#hit').click(function() { alert($('#term').val()); }); }); </script> </body> </html>

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!