javascript - wrong ASCII key code for delete key -
i have html form in need allow numeric key-press. have used following code
$(".span8").keypress(function(e) { var unicode=e.charcode? e.charcode : e.keycode //alert(unicode); if ((unicode ==8) || (unicode==9)|| (unicode==46)){ //if key isn't backspace key (which should allow) } else { if (unicode<48||unicode>57&&unicode!=65) //if not number return false //disable key press } });
but here if testing keycode, getting value 46 delete key. 46 dot(- period) others values coming correct. not able find going wrong. please
i've found weird behaviour keypress
function.
instead, try following:
jquery(function($) { var input = $('.span8'); input.on('keydown', function() { var key = event.keycode || event.charcode; if(key == 8 || key == 46) //do when del or backspace pressed }); });
Comments
Post a Comment