P粉4312202792023-08-23 22:08:13
You can try event.key
, event.keyCode
, event.which
.
If none of the above works, you can try event.target.value.splice(-1)
P粉5502578562023-08-23 19:41:36
keydown
should work, but you can use the input
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:
input
event (e.which
is always 0
, so seems to be a bug on Android devices) jQuery(function($) { // DOM准备就绪和$别名已保证 $('#buscar-producto').on('input', function(e){ var key = e.which || this.value.substr(-1).charCodeAt(0); alert( key ) }); });
<input type="text" id="buscar-producto" placeholder="搜索..."> <script src="https://code.jquery.com/jquery-3.1.0.js"></script>