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

129
Views
Mostrar valores de entrada en la etiqueta ap

Tengo un elemento de entrada, lo que quiero lograr es que cada vez que escriba en la entrada, los caracteres se insertarán en la etiqueta ap y se mostrarán. El código que tengo a continuación funciona parcialmente. El problema que tengo con mi código es que los caracteres comenzarán a mostrarse en la etiqueta p cuando escribo el segundo carácter. Quiero que comience a mostrarse después del primer carácter escrito. ¿Cómo puedo conseguir esto?

 $('input').keypress(function() { if ($(this).val().length >= 0) { $('p').html($(this).val()) } }); $('input').keyup(function(e) { if (e.keyCode == 8) { if ($(this).val() == "" || $(this).val() == null) { $('p').html('') } $('p').html($(this).val()) } })
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <input /> <p></p>

about 4 years ago · Santiago Gelvez
2 answers
Answer question

0

Creo que el evento de input es ideal para este caso. También atrapa copiar y pegar en el campo.

 $('input').on('input', function() { $('p').html($(this).val()) });
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <input /> <p></p>

about 4 years ago · Santiago Gelvez Report

0

Solo usa la función de teclado.

 $('input').keyup(function() { if ($(this).val().length >= 0) { $('p').html($(this).val()) } }); $('input').keydown(function(e) { if (e.keyCode == 8) { if ($(this).val() == "" || $(this).val() == null) { $('p').html('') } $('p').html($(this).val()) } })
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <input /> <p></p>

about 4 years ago · Santiago Gelvez 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!