Há muitos exemplos sobre keypress, keyup... em jQuery. Estes exemplos são sobre digitação no campo de texto. Quando o usuário digita uma mensagem ou algo no campo de texto, podemos exibir algo como Usuário está digitando, mas não podemos exibir uma mensagem sobre a situação quando o usuário não digita. Aqui está um exemplo de http://api.jquery.com/keypress/:
$("#target").keypress(function() {
$("#other).html("User is typing");
});
<form>
<fieldset>
<input id="target" type="text" value="" />
</fieldset>
</form>
<div id="other">
Trigger the handler
</div>
Como posso alterar este código e exibir mensagem (usuário não está digitando) quando ele não digita? Algo como mais opção ....
EDIT: aqui é minha idéia. É semelhante com a sua ideia (código). Obrigado por ajudar.
$(document).ready(function(){
$("#target").keyup(function(){
setTimeout(function(){
$("#other").html("User is not typing");
}, 2000);
});
$("#target").keydown(function(){
$("#other").html("User is typing");
});
});
Respostas:
1 para resposta № 1Eu sugiro usar atraso:
$("#target").keypress(function() {
$("#other").html("User is typing");
$("#other").delay(1000).queue(function(n) {
$(this).html("User is not typing");
n();
});
});