js通过keyCode值判断单击键盘上某个键,然后触发指定的事件方法
当单击按键时触发事件
document.onkeydown = function (e) { e = e || event; if (e.keycode == 13) { //判断是否单击的enter按键(回车键) document.getelementbyidx_x_x("txtid").click(); return false; } }
解释:keycode的值表示对应键盘的那个键
keycode 8 = backspace backspace
keycode 9 = tab tab
keycode 12 = clear
keycode 13 = enter
keycode 16 = shift_l
keycode 17 = control_l
keycode 18 = alt_l
keycode 19 = pause
keycode 20 = caps_lock
keycode 27 = escape escape
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 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 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 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 187 = acute grave
keycode 188 = comma semicolon
keycode 189 = minus underscore
keycode 190 = period colon
keycode 192 = numbersign apostrophe
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 220 = less greater bar
keycode 221 = plus asterisk asciitilde
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
以上这篇js通过keycode值判断单击键盘上某个键,然后触发指定的事件方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。