Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

159
Visualizações
jQuery focus and select on next input not working

I use focus() and also select() to focus and select next element, but this work fine in desktop,and also chrome device view (mobile) but not working in smartphone like android (I tested in chrome browser), any idea how to solve this problem?

$('.verf-code input').on('keypress',function(e) {
  var key = e.which;

  if (key >= 48 && key <= 57) {
    $(this).addClass('hasCode').next('input').select().focus();
    return true;
  } else if (key == 8 || key == 46) {
    $(this).removeClass('hasCode');
  } else {
    return false;
  }

});
.hasCode {
border: 1px solid orange;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="verf-code">
  <input type="text" />
  <input type="text" />
  <input type="text" />
  <input type="text" />
</div>

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Try this:

$(".verf-code input").on("keyup", function (e) {
    var key = e.which;
    if ($(this).val() !== '') {
         $(this).addClass('hasCode').next('input').select().focus();
    }else if(key == 8 || key == 46){
        $(this).removeClass('hasCode');
    }
});
    .hasCode {
        border: 1px solid orange;
    }
    input::-webkit-outer-spin-button,
    input::-webkit-inner-spin-button {
      -webkit-appearance: none;
      margin: 0;
    }
    input[type=number] {
      -moz-appearance: textfield;
    }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="verf-code">
    <input type="number" />
    <input type="number" />
    <input type="number" />
    <input type="number" />
</div>

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda