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

123
Visualizações
set new value with windows.prevFocus

I have set up previous focus storage in my document. When the button is clicked, a function gets executed. The value 0 is transported as a variable from the button to the function. In the function the new value is set to the previous focussed element. But it doesn't work. Why not? The reason why I do it this way is because I have more buttons, that give different values but only have to use the same function: setNewValue

Main script:

window.prevFocus = $();
// Catch any bubbling focusin events (focus does not bubble)
$(document).on('focusin', ':input', function () {
   // Test: Show the previous value
   $("#debug").html(prevFocus.attr("id"));
   // Save the previously clicked value for later
   window.prevFocus = $(this);
});

Button script

$("#butSetVal0").on({ 
    click: function(){
        newVal = 0;
        setNewValue(newVal);
    }
});

set new value script:

function setNewValue(newVal){
    prevFocus.val(newVal).trigger("input");
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I fixed it already. The solution is to set the eventhandler of the button on 'mousedown'. The 'click' trigger detects two clicks. The second click interprets as the previous focus element, so the button itself.

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