1
$('#a').keyup(
  function(event){
   alert(event.keyValue)
  }
)

but error,coz 'keyValue' is not undefined,

how do i get the keyValue when the event keyup???

i use jquery.

thanks


i do this:

$('#a').keyup(
  function(event){
   alert(String.fromCharCode(event.which))
  }

but it alert the value of upper

ex:

i alert I

l alert L

why??? )

Trott
  • 66,479
  • 23
  • 173
  • 212
zjm1126
  • 63,397
  • 81
  • 173
  • 221
  • You mean it's changing the case on you? That definitely shouldn't be happening and has never happened to me in either FF3.5, IE6-7-8, Safari or Chrome using jQuery 1.4.1. What browser are you using? What version of jQuery? – leepowers Feb 15 '10 at 02:43
  • my browser is firefox ,and i test it in chrome ,it is the same result. – zjm1126 Feb 15 '10 at 03:01

3 Answers3

1

try event.keyCode instead

Marius
  • 57,995
  • 32
  • 132
  • 151
1

JQuery places the key pressed into event.which across all browsers.

See here: http://api.jquery.com/keyup/

To determine which key was pressed, we can examine the event object that is passed to the handler function. While browsers use differing attributes to store this information, jQuery normalizes the .which attribute so we can reliably use it to retrieve the key code

leepowers
  • 37,828
  • 23
  • 98
  • 129
0

Check out this question: jQuery Event Keypress: Which key was pressed?

Community
  • 1
  • 1
PetersenDidIt
  • 25,562
  • 3
  • 67
  • 72