导航:首页 > 编程语言 > js监听enter

js监听enter

发布时间:2024-07-07 21:30:21

『壹』 关于js中事件监听的问题(文本框 回车键 失去焦点)

你可以在输入框里面一个js事件onkeydown=“document.getElementById('确定按钮的Id').focus()”
如果还不行把你的代码贴出来我看下

『贰』 js如何判断光标是否在某元素上

判断光标是否在某元素上可以在window监听onmouseenter(onmouseleave)或者onmouseover(onmouseout)给某变量赋值1(赋值0),那么变量为1则在元素上(0则不在元素上)
window.onmouseover = function () { isOn = 1};
window.onmouseout = function () { isOn = 0};
window中mouse相关事件补充:
onmousedown 鼠标按钮被按下 (和onmouseup组成了单击事件);
onmouseenter 当鼠标指针移动到元素上时触发 (只在进入后触发一次,不支持冒泡,子元素不触发);
onmouseleave 当鼠标指针移出元素时触发 (只在离开后触发一次,支持冒泡,子元素也可以触发);
onmousemove 鼠标被移动 (在元素内移动会一直触发);
onmouseover 鼠标移到某元素之上 (只在进入后触发一次,支持冒泡,子元素也可以触发);
onmouseout 鼠标从某元素移开 (只在离开后触发一次,支持冒泡,子元素也可以触发);
onmouseup 鼠标按键被松开;

『叁』 怎么在JS中增加键盘监听

键盘的每个键都有对应的事件值,用按键按下或抬起事件,就可以绑定了,事件和对应值如下:
1、keydown()
keydown事件会在键盘按下时触发.
2、keyup()
keyup事件会在按键释放时触发,也就是你按下键盘起来后的事件
3、keypress()
keypress事件会在敲击按键时触发,我们可以理解为按下并抬起同一个按键

对应值:
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 = right 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怎么写一个回车键盘事件

<script type="text/javascript" language=JavaScript charset="UTF-8">

document.onkeydown=function(event){

var e = event || window.event || arguments.callee.caller.arguments[0];

if(e && e.keyCode==27){ // 按 Esc

//要做的事情

}

if(e && e.keyCode==113){ // 按 F2

//要做的事情

}

if(e && e.keyCode==13){ // enter 键

//要做的事情

}

};

</script>

(4)js监听enter扩展阅读:

Js键盘事件

keydown:按键按下

keyup:按键抬起

keypress:按键按下抬起

<body>

<input id="name" type="text" onkeydown="myKeyDown(this.id)" onkeyup="myKeyUp(this.id)">

</body>

<script>

/*输出输入的字符*/

function myKeyDown(id) {

console.log(document.getElementById(id).value);

}

/*按键结束,字体转换为大写*/

function myKeyUp(id) {

var text = document.getElementById(id).value;

document.getElementById(id).value = text.toUpperCase();

}

</script>

常用的键盘事件对应的键码:

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

『伍』 JS 怎么实现按钮按下时,相当于空格键效果

 JS实现绑定事件监听的几种方法 一、行内绑定 行内绑定:在HTML的标签中通过onclick属性进行绑定,绑定方式:on+事件名,在将所触发的事件赋值给该属性,如下: <button onclick="alert('123');">点击</button> 二、使用element.onclick进行事件绑定 使用element

『陆』 JS锛孷ue2锛屼簨浠跺勭悊锛岃$畻灞炴э紝鐩戣嗗睘鎬э紝class涓巗tyle缁戝畾

鐢╲-on鎸囦护鎴栬匑鐩戝惉DOM浜嬩欢锛屽苟鍦ㄨЕ鍙戞椂杩愯屼竴浜汮avaScript浠g爜锛

鍙傝冿細JS锛孷ue2锛屼粙缁嶏紝涓嶸ue3鍖哄埆锛孧VVM璁捐℃ā寮忥紝妯℃澘璇娉曪紝鏁版嵁缁戝畾

Vue涓鐨勪簨浠朵慨楗扮︼細

1銆乸revent锛氶樆姝㈤粯璁や簨浠讹紙甯哥敤锛夛紱

2銆乻top锛氶樆姝浜嬩欢鍐掓场锛堝父鐢锛夛紱

3銆乷nce锛氫簨浠跺彧瑙﹀彂涓娆★紙甯哥敤锛夛紱

4銆乧apture锛氫娇鐢ㄤ簨浠剁殑鎹曡幏妯″紡锛

5銆乻elf锛氬彧鏈塭vent.target鏄褰撳墠鎿嶄綔鐨勫厓绱犳椂鎵嶈Е鍙戜簨浠讹紱

6銆乸assive锛氫簨浠剁殑榛樿よ屼负绔嬪嵆鎵ц岋紝鏃犻渶绛夊緟浜嬩欢鍥炶皟鎵ц屽畬姣曪紱

Vue涓甯哥敤鐨勬寜閿鍒鍚嶏細

鍥炶溅 => enter銆佸垹闄 => delete (鎹曡幏鈥滃垹闄も濆拰鈥滈鏍尖濋敭)銆侀鍑 => esc銆佺┖鏍 => space銆佹崲琛 => tab (鐗规畩锛屽繀椤婚厤鍚坘eydown鍘讳娇鐢)銆佷笂 => up銆佷笅 => down銆佸乏 => left銆佸彸 => right绛夈

浠g爜妗堜緥

妯℃澘鍐呯殑琛ㄨ揪寮忔槸闈炲父渚垮埄鐨勶紝鐢ㄤ簬绠鍗曠殑杩愮畻銆傚綋鍏惰繃闀挎垨閫昏緫杩囦簬澶嶆潅鏃讹紝浼氶毦浠ョ淮鎶わ紝鍥犳わ紝褰撻亣鍒板嶆潅鐨勯昏緫鏃跺簲璇ヤ娇鐢ㄨ$畻灞炴э紝鐢╟omputed璁$畻灞炴с

浠g爜妗堜緥

閫氳繃watch鏉ュ搷搴旀暟鎹鐨勫彉鍖栥

浠g爜妗堜緥

class鏍峰紡锛屽啓娉:class="xxx" 锛屽叾涓瓁xx鍙浠ユ槸瀛楃︿覆銆佸硅薄銆佹暟缁勩

1銆佸瓧绗︿覆鍐欐硶閫傜敤浜庯細绫诲悕涓嶇‘瀹氾紝瑕佸姩鎬佽幏鍙栥

2銆佸硅薄鍐欐硶閫傜敤浜庯細瑕佺粦瀹氬氫釜鏍峰紡锛屼釜鏁颁笉纭瀹氾紝鍚嶅瓧涔熶笉纭瀹氥

3銆佹暟缁勫啓娉曢傜敤浜庯細瑕佺粦瀹氬氫釜鏍峰紡锛屼釜鏁扮‘瀹氾紝鍚嶅瓧涔熺‘瀹氾紝浣嗕笉纭瀹氱敤涓嶇敤銆

style鏍峰紡锛屽啓娉曪細:style="{fontSize: xxx}"锛屽叾涓瓁xx鏄鍔ㄦ佸硷紱:style="[a,b]"鍏朵腑a銆乥鏄鏍峰紡瀵硅薄銆

浠g爜妗堜緥

阅读全文

与js监听enter相关的资料

热点内容
文档转成pdf格式文件 浏览:621
离子数据怎么写 浏览:876
jspapijar官网下载 浏览:366
html调用文本文件 浏览:921
想学数控编程哪里好 浏览:860
js获取系统动态时间间隔 浏览:165
win10改win7进pe卡住 浏览:456
u盘中毒ink文件 浏览:718
苹果换机数据迁移包含哪些数据 浏览:234
程控可编程直流电源在哪里 浏览:598
容积长宽高的数据从什么面测量 浏览:978
苹果手游工作室 浏览:362
数据型号特别多怎么合并 浏览:600
企业微信电脑版怎么无法接受文件 浏览:968
微信个人相册怎么隐藏 浏览:368
上传文件时怎么获取文件全路径 浏览:955
linuxjs读取文件 浏览:104
exe后缀的pdf文件 浏览:381
win8升级到专业版 浏览:487
快图浏览quickpiciphone 浏览:847

友情链接