Summary of Event object attributes in Jquery, jqueryevent
The JS Event object is an object that is passed to the Event processing function when an Event is triggered. This object contains the basic information for triggering the Event. Such as the event source and keyboard code (if any) of the trigger event.
1. Get the event type through event. type
Copy codeThe Code is as follows:
<Script>
$ (Function (){
$ ("A"). click (function (event ){
Alert (event. type); // obtain the event type
// Return false; // block link jump
Event. preventDefault ();
});
})
</Script>
2. Get the attribute value of the event Target
The html code is as follows:
Copy codeThe Code is as follows:
<Body>
<A href = 'HTTP: // google.com '> click me. </a>
</Body>
Copy codeThe Code is as follows:
<Script>
$ (Function (){
$ ("A [href = http://google.com]"). click (function (event ){
Alert(event.tar get. href); // gets the href attribute value of the <a> element of the trigger event
Return false; // block link jump
});
})
</Script>
You can obtain the href value of the attribute 'HTTP: // google.com '.
3. Obtain the coordinate values x and y corresponding to the mouse.
Copy codeThe Code is as follows:
<Script>
$ (Function (){
$ ("A"). click (function (e ){
Alert ("Current mouse position:" + e. pageX + "," + e. pageY); // obtain the coordinates of the Current mouse relative to the page
Return false; // block link jump
});
})
</Script>
The parameter name passed here is not necessarily an event, but can be any name. The default value is event. If you do not specify a parameter, an event parameter is input by default.
4. The which attribute can be used to obtain the corresponding event value.
The which attribute indicates which key or button is pressed.
Copy codeThe Code is as follows:
<Script>
$ (Function (){
$ ("A"). mousedown (function (e ){
Alert (e. which) // 1 = left mouse button; 2 = middle mouse button; 3 = right mouse button
Return false; // block link jump
})
})
</Script>
For details about how to obtain the Keycode value of a key in Javascript, refer:
Copy codeThe Code is as follows:
Keycode 8 = BackSpace
Keycode 9 = 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
Keycode 32 = 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
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
Keycode 82 = r R
Keycode 83 = s
Keycode 84 = t T
Keycode 85 = u U
Keycode 86 = v V
Keycode 87 = w
Keycode 88 = x X
Keycode 89 = y 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
Keycode 107 = KP_Add
Key code 108 = KP_Separator
Keycode 109 = KP_Subtract
Key code 110 = KP_Decimal
Keycode 111 = KP_Divide
Key code 112 = F1
Keycode 113 = F2
Key code 114 = F3
Keycode 115 = F4
Key code 116 = F5
Keycode 117 = F6
Key code 118 = F7
Key code 119 = F8
Keycode 120 = F9
Keycode 121 = F10
Keycode 122 = F11
Key Code 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
Key code 189 = minus underscore
Key code 190 = period colon
Key code 192 = numbersign apostrophe
Key Code 210 = plusminus hyphen macron
Key code 212 = copyright registered
Key code 213 = guillemotleft guillemotright
Keycode 214 = masculine ordfeminine
Keycode 215 = AE AE
Keycode 216 = cent yen
Key code 217 = questiondown exclamdown
Key code 218 = onequarter onehalf threequarters
Keycode 220 = less greater bar
Key code 221 = plus asterisk asciitilde
Key code 227 = multiply division
Keycode 228 = acircumflex Acircumflex
Key code 229 = ecircumflex Ecircumflex
Keycode 230 = icircumflex Icircumflex
Key code 231 = ocircumflex Ocircumflex
Keycode 232 = ucircumflex Ucircumflex
Keycode 233 = ntilde Ntilde
Keycode 234 = yacute Yacute
Key code 235 = oslash Ooblique
Key Code 236 = aring Aring
Keycode 237 = ccedilla Ccedilla
Key code 238 = thorn THORN
Keycode 239 = eth ETH
Key code 240 = diaeresis cedilla currency
Key code 241 = agrave Agrave atilde Atilde
Keycode 242 = egrave Egrave
Keycode 243 = igrave Igrave
Key code 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
Key code 251 = ssharp question backslash
Keycode 252 = asciicircum degree
Keycode 253 = 3 sterling
Keycode 254 = Mode_switch
The above is the key value reference in js, among which 13 (enter), 32 (Space), 27 (ESC), 16 (Shift), 17 (Ctrl ), 18 (Alt ).
More values can be obtained through jQuery below:
Copy codeThe Code is as follows:
<Script>
$ (Function (){
$ ("Input"). keyup (function (e) {// obtain the value of the keyup time
Alert (e. which );
})
})
</Script>