Trigger the keyup handler onfocus:
$('#input').on('focus',function(){
this.value='';
$(this).keyup();
});
题
If I use this: <input class="search" type="text" id="input" onfocus="this.value=''" />
and I write for example: arduino
and it searches for everything with the text arduino
and after that I click on somewhere else on the webpage and then click on the input field again, the text clears out as it should, but I have to backspace
once on my keyboard, to clear the results for arduino
and show everything.
Why and how can I fix this? Thanks
解决方案
Trigger the keyup handler onfocus:
$('#input').on('focus',function(){
this.value='';
$(this).keyup();
});
其他提示
Try this to clear search and show everything back:
$("input[type=text]").focus(function(){
$(this).val('');
$('.input').hide();
$("ul.filter li").show();
});