Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

177
Vistas
Alerta de evento ONFOCUS llamando varias veces

Hola, busque el siguiente código y ayude a resolver el problema.

 <html> <body> <script src="https://code.jquery.com/jquery-3.6.0.js" integrity="sha256-H+K7U5CnXl1h5ywQfKtSj8PCmoN9aaq30gDh27Xc0jk=" crossorigin="anonymous"></script> <script> function fnAlertTitle(){ var strTitleFlag =document.test.fname.value.trim(); console.log("strTitleFlag::"+strTitleFlag); if (strTitleFlag == "") { alert("Please Select Fname"); document.test.fname.focus(); window.event.returnValue =false; return; } } $('body').on('keydown', 'input, select', function(e) { if (e.key === "Enter") { var self = $(this), form = self.parents('form:eq(0)'), focusable, next; focusable = form.find('input,a,select,button,textarea').filter(':visible'); next = focusable.eq(focusable.index(this)+1); if (next.length) { next.focus(); } else { form.submit(); } return false; } }); </script> <h1>The input element</h1> <form name="test" action=""> <label for="fname">First name:</label> <input type="text" id="fname" name="fname" tabindex="1"><br><br> <label for="lname">Last name:</label> <input type="text" id="lname" name="lname" tabindex="2" onFocus="javascript:fnAlertTitle();"><br><br> <input type="submit" value="Submit"> </form> </body> </html>

Al presionar la pestaña ONFOCUS, el evento llama una vez, pero mientras presiona ingresar su llamada varias veces, ayude a resolver el problema

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Puede eliminar onFocus="javascript:fnAlertTitle();" desde HTML y realice pequeños cambios en su código como se muestra a continuación:

 function fnAlertTitle(){ ... if (strTitleFlag == "") { ... return true; } } $('body').on('keydown', 'input, select', function(e) { if (e.key === "Enter") { if(fnAlertTitle()) return; var self = ... } });
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda