jquery - e.which: Non numeric comparison -


After

I have a legacy jQuery method that starts like this:

  $ (function () {$ (Document) .keypress (function (e) {if ($ (document.activeElement) .is ('body')) {if (e.which == 48) {//  < / Pre> 

I want to clear the code to clean it.

How can I check that the user has pressed the '0' key?

If the code works, it might be without magic number, but you want:, or you if (e.which == unkown_method ('0')) {... Solution

I can now use this solution with the help of "Archer" using the code>

I:

  var key = String.fromCharCode (e.which); if (key == "0") {...} else if (key == "5") {. ..}    

If you are asking if I think you are asking Then it should help ...

  if (String.fromCharCode (e.which) == "0") {etc ..   

Edit This next bit is actually not relevant after y is relevant Supports jQuery standardized, so it always uses which , but I will leave it for reference.


Also, keep in mind that different browsers are slightly different event types, so you may have to include it.

  var key = String.fromCharCode (E.keyCode? E.keycode: e.which); If (key == "0") {etc.}   

This is a normal bit of code that I've made a goal for ever, and to be honest, I do not remember what to do, but some use keycode And some use which is in both events including

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -