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

93
Views
Cómo mover el foco al siguiente elemento al ingresar en la selección creada dinámicamente

El formulario html contiene elementos de entrada.

El código Javascript y jquery se usa para crear un elemento seleccionado en tiempo de ejecución e insertarlo después del elemento elem y asignarle la clase Bootstrap 5:

 let selectArray = ["Intv Scheduled", "Selected", "Rejected", "On Hold"]; let id = 'Customer'; $('#' + id).remove(); var selectList = document.createElement("select"); selectList.id = selectList.name = id; selectList.className = "form-select"; elem.after(selectList); for (var i = 0; i < selectArray.length; i++) { var option = document.createElement("option"); option.value = option.text = selectArray[i]; selectList.appendChild(option); } selectList.focus();

El usuario selecciona el elemento usando la tecla enter. Después de presionar enter, el elemento seleccionado aún está enfocado.

¿Cómo mover el foco al siguiente elemento en el formulario si se presiona enter?
¿Cómo reemplazar $('#' + id).remove() con JavaScript simple para que se pueda eliminar la dependencia de jQuery?

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

0

Hay dos métodos JavaScript puros para reemplazar la función $(...).remove() en jQuery.

Solución uno: la función .remove() .

 let id = ""; // Find the element then remove it document.getElementById(id).remove();

Referencia:

  • https://developer.mozilla.org/en-US/docs/Web/API/Element/remove

Solución dos: encontrar el nodo principal y luego usar el método .removeChild() .

 let id = ""; // Find the element mentioned let element = document.getElementById(id); // Find the elements parent node let parent = element.parentNode; // Remove the element from the parent parent.removeChild(element);

Referencia:

  • https://developer.mozilla.org/en-US/docs/Web/API/Node/removeChild
about 4 years ago · Juan Pablo Isaza Report

0

Un poco difícil de adivinar lo que estás pidiendo.

Ya hay múltiples sugerencias y respuestas disponibles en SO.

La pulsación de la tecla Intro se comporta como una pestaña en Javascript

 document.addEventListener('keydown', function (e) { if (event.keyCode === 13 && event.target.nodeName == 'SELECT') { var form = event.target.closest('form'); var index = Array.prototype.indexOf.call(form, event.target); form.elements[index + 1].focus(); return false; } });
 <form> <div id = "Customer">Customer</div> <select> <option value = "">Test</option> <option value = "">Test</option> </select> <input type = "text"> <select> <option value = "">Test</option> <option value = "">Test</option> </select> <select> <option value = "">Test</option> <option value = "">Test</option> </select> <input type = "text"> </form>

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!