How to define a SHIFT key in jQuery keydown event handler?

I have the following jQuery function

jQuery.fn.integerMask = function () { return this.each(function () { $(this).keydown(function (e) { var key = (e.keyCode ? e.keyCode : e.which); // allow backspace, tab, delete, arrows, numbers and keypad numbers ONLY return ( key == 8 || key == 9 || key == 46 || key == 37 || key == 39 || (key >= 48 && key <= 57) || (key >= 96 && key <= 105)); ); }); }); }; 

which is used to enter numbers. The problem is that SHIFT + 8 causes an asterisk * to be entered. The "8" key in combination with SHIFT seems to be enabled. How can I prevent reception of SHIFT + 8 and insert the character "*"?

+4
source share
1 answer
 <!DOCTYPE html> <html> <head> <script> function isKeyPressed(event) { if (event.shiftKey==1) { alert("The shift key was pressed!"); } else { alert("The shift key was NOT pressed!"); } } </script> </head> <body onmousedown="isKeyPressed(event)"> <p>Click somewhere in the document. An alert box will tell you if you pressed the shift key or not.</p> </body> </html> 

keyword-> event.shiftKey

Source: http://www.w3schools.com/jsref/tryit.asp?filename=try_dom_event_shiftkey

-1
source

All Articles