欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Jquery页面中添加键盘按键事件,如ESC事件

程序员文章站 2022-08-11 21:34:11
1.给整个页面添加ESC事件: $(document).keyup(function(event){ switch(event.keyCode) { case 27: alert("ESC"); case 96: alert("ESC"); } }); 2.给指定元素添加ESC事件: 当按下一个键盘 ......

1.给整个页面添加esc事件:

$(document).keyup(function(event){

 switch(event.keycode) {
 case 27:
 alert("esc");
 case 96:
 alert("esc");
 }

});

2.给指定元素添加esc事件:

当按下一个键盘按键时触发onkeydown事件

keycode   0 =
keycode   1 =
keycode   2 =
keycode   3 =
keycode   4 =
keycode   5 =
keycode   6 =
keycode   7 =
keycode   8 = backspace backspace
keycode   9 = tab tab
keycode 10 =
keycode 11 =
keycode 12 = clear
keycode 13 = enter
keycode 14 =
keycode 15 =
keycode 16 = shift_l
keycode 17 = control_l
keycode 18 = alt_l
keycode 19 = pause
keycode 20 = caps_lock
keycode 21 =
keycode 22 =
keycode 23 =
keycode 24 =
keycode 25 =
keycode 26 =
keycode 27 = escape escape
keycode 28 =
keycode 29 =
keycode 30 =
keycode 31 =
keycode 32 = space space
keycode 33 = prior
keycode 34 = next
keycode 35 = end
keycode 36 = home
keycode 37 = left
keycode 38 = up
keycode 39 = right
keycode 40 = down
keycode 41 = select
keycode 42 = print
keycode 43 = execute
keycode 44 =
keycode 45 = insert
keycode 46 = delete
keycode 47 = help
keycode 48 = 0 equal braceright
keycode 49 = 1 exclam onesuperior
keycode 50 = 2 quotedbl twosuperior
keycode 51 = 3 section threesuperior
keycode 52 = 4 dollar
keycode 53 = 5 percent
keycode 54 = 6 ampersand
keycode 55 = 7 slash braceleft
keycode 56 = 8 parenleft bracketleft
keycode 57 = 9 parenright bracketright
keycode 58 =
keycode 59 =
keycode 60 =
keycode 61 =
keycode 62 =
keycode 63 =
keycode 64 =
keycode 65 = a a
keycode 66 = b b
keycode 67 = c c
keycode 68 = d d
keycode 69 = e e eurosign
keycode 70 = f f
keycode 71 = g g
keycode 72 = h h
keycode 73 = i i
keycode 74 = j j
keycode 75 = k k
keycode 76 = l l
keycode 77 = m m mu
keycode 78 = n n
keycode 79 = o o
keycode 80 = p p
keycode 81 = q q at
keycode 82 = r r
keycode 83 = s s
keycode 84 = t t
keycode 85 = u u
keycode 86 = v v
keycode 87 = w w
keycode 88 = x x
keycode 89 = y y
keycode 90 = z z
keycode 91 =
keycode 92 =
keycode 93 =
keycode 94 =
keycode 95 =
keycode 96 = kp_0 kp_0
keycode 97 = kp_1 kp_1
keycode 98 = kp_2 kp_2
keycode 99 = kp_3 kp_3
keycode 100 = kp_4 kp_4
keycode 101 = kp_5 kp_5
keycode 102 = kp_6 kp_6
keycode 103 = kp_7 kp_7
keycode 104 = kp_8 kp_8
keycode 105 = kp_9 kp_9
keycode 106 = kp_multiply kp_multiply
keycode 107 = kp_add kp_add
keycode 108 = kp_separator kp_separator
keycode 109 = kp_subtract kp_subtract
keycode 110 = kp_decimal kp_decimal
keycode 111 = kp_divide kp_divide
keycode 112 = f1
keycode 113 = f2
keycode 114 = f3
keycode 115 = f4
keycode 116 = f5
keycode 117 = f6
keycode 118 = f7
keycode 119 = f8
keycode 120 = f9
keycode 121 = f10
keycode 122 = f11
keycode 123 = f12
keycode 124 = f13
keycode 125 = f14
keycode 126 = f15
keycode 127 = f16
keycode 128 = f17
keycode 129 = f18
keycode 130 = f19
keycode 131 = f20
keycode 132 = f21
keycode 133 = f22
keycode 134 = f23
keycode 135 = f24
keycode 136 = num_lock
keycode 137 = scroll_lock
keycode 138 =
keycode 139 =
keycode 140 =
keycode 141 =
keycode 142 =
keycode 143 =
keycode 144 =
keycode 145 =
keycode 146 =
keycode 147 =
keycode 148 =
keycode 149 =
keycode 150 =
keycode 151 =
keycode 152 =
keycode 153 =
keycode 154 =
keycode 155 =
keycode 156 =
keycode 157 =
keycode 158 =
keycode 159 =
keycode 160 =
keycode 161 =
keycode 162 =
keycode 163 =
keycode 164 =
keycode 165 =
keycode 166 =
keycode 167 =
keycode 168 =
keycode 169 =
keycode 170 =
keycode 171 =
keycode 172 =
keycode 173 =
keycode 174 =
keycode 175 =
keycode 176 =
keycode 177 =
keycode 178 =
keycode 179 =
keycode 180 =
keycode 181 =
keycode 182 =
keycode 183 =
keycode 184 =
keycode 185 =
keycode 186 =
keycode 187 = acute grave
keycode 188 = comma semicolon
keycode 189 = minus underscore
keycode 190 = period colon
keycode 191 =
keycode 192 = numbersign apostrophe
keycode 193 =
keycode 194 =
keycode 195 =
keycode 196 =
keycode 197 =
keycode 198 =
keycode 199 =
keycode 200 =
keycode 201 =
keycode 202 =
keycode 203 =
keycode 204 =
keycode 205 =
keycode 206 =
keycode 207 =
keycode 208 =
keycode 209 =
keycode 210 = plusminus hyphen macron
keycode 211 =
keycode 212 = copyright registered
keycode 213 = guillemotleft guillemotright
keycode 214 = masculine ordfeminine
keycode 215 = ae ae
keycode 216 = cent yen
keycode 217 = questiondown exclamdown
keycode 218 = onequarter onehalf threequarters
keycode 219 =
keycode 220 = less greater bar
keycode 221 = plus asterisk asciitilde
keycode 222 =
keycode 223 =
keycode 224 =
keycode 225 =
keycode 226 =
keycode 227 = multiply division
keycode 228 = acircumflex acircumflex
keycode 229 = ecircumflex ecircumflex
keycode 230 = icircumflex icircumflex
keycode 231 = ocircumflex ocircumflex
keycode 232 = ucircumflex ucircumflex
keycode 233 = ntilde ntilde
keycode 234 = yacute yacute
keycode 235 = oslash ooblique
keycode 236 = aring aring
keycode 237 = ccedilla ccedilla
keycode 238 = thorn thorn
keycode 239 = eth eth
keycode 240 = diaeresis cedilla currency
keycode 241 = agrave agrave atilde atilde
keycode 242 = egrave egrave
keycode 243 = igrave igrave
keycode 244 = ograve ograve otilde otilde
keycode 245 = ugrave ugrave
keycode 246 = adiaeresis adiaeresis
keycode 247 = ediaeresis ediaeresis
keycode 248 = idiaeresis idiaeresis
keycode 249 = odiaeresis odiaeresis
keycode 250 = udiaeresis udiaeresis
keycode 251 = ssharp question backslash
keycode 252 = asciicircum degree
keycode 253 = 3 sterling
keycode 254 = mode_switch