Issues with keyup, keydown and keypress events on mobile devices
P粉461599845
2023-08-22 23:26:57
<p><br /></p>
<p>I've been trying to get it to work but I don't know what's going on, I have the following code: </p>
<pre class="brush:php;toolbar:false;">$('#buscar-producto').on('keydown', function(e){
console.log('hello');
console.log(e.keyCode);
});</pre>
<p>It works on a computer but not on a phone...</p>
<p><strong>Edit:</strong> I need to get the keyCode when the key is pressed...</p>
You can try
event.key
,event.keyCode
,event.which
.If none of the above works, you can try
event.target.value.splice(-1)
keydown
should work, but you can use theinput
event, which seems to have a bad effect on Android mobile devices...To get the code of a pressed key, you can use jQuery's normalized
Event.which
Tested Android Chrome:
Use the
input
event (e.which
is always0
, so seems to be a bug on Android devices)