『壹』 關於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>
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爜妗堜緥