Created
October 27, 2016 13:44
-
-
Save lena121/5b0212d28488769f7894dbef957014e9 to your computer and use it in GitHub Desktop.
JS events (DOM level2)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
addEventListener("event", handler, capture) - where | |
"event" - name of event, | |
handler - function(e){} - function which handle event | |
e - object of event, | |
capture - (true, false) | |
capture=true - event executes on the first phaze (на этапе перехвата) | |
capture=false - event executes on the third phaze (на этапе всплытия) | |
removeEventListener("event", handler, capture) | |
------------------------------------------------------------------------------------------------------------------------------- | |
MAIN EVENTS | |
onfocus - gets focus on element (button, input, label, select, textarea, body) | |
onblur - element lose focus from itself (button, input, label, select, textarea, body) | |
onchange - при порете фокуса в случае наличия изменений значения в элементе управления (input, select, textarea) | |
onclick | |
ondbclick | |
onerror - error while image load (img) | |
onkeydown - клавиша нажата (элементы формы и body) | |
onkeypress - клавиша нажата и отпущена (элементы формы и body) | |
onkeyup -клавиша отпущена (элементы формы и body) | |
onload - загрузка полностью завершена (body, img) | |
onresize - изменений размера окна (body) | |
onmousedown - нажата кнопка мыши | |
onmouseup - отпущена кнопка мыши | |
onmousemove - перемещение указателя мыши | |
onmouseout - указатель мыши выходит за границы элемента | |
onmouseover - указатель мыши находит на элемент | |
onreset - запрос на очистку полей формы | |
onsubmit - запрос на передачу данных формы | |
( naming events on-* is applicable for model DOM level0, | |
all events for DOM level2 have name without prefix on- ) | |
-------------------------------------------------------------------------------------------------------------------------------- | |
e - event object (объект события, который создаётся перед запуском события и передаётся в функцию-обработчик события) | |
e.type - тип события, строковое значение | |
e.target - содержит ссылку на элемент, который был инициатором события | |
e.currentTarget - элемент, на который повешен обработчик события (текущий элемент, который в данный момент обрабатывает событие) | |
e.eventPhase - число, указывающее этап | |
CAPTURING_PHASE = 1, | |
AT_TARGET = 2, | |
BUBBLING_PHASE = 3 | |
e.timeStamp - объект Datе, указыввающий когда произошло событие | |
e.bubbles - true, если событие может всплывать по дереву элементов (дело в том, | |
что некоторые события не поддерживают этап вспывания. Это blur, focus, load, unload) | |
e.cancelable - true, если с этим событием связано действие по умолчанию, которое можно отменить вызовом метода preventDefault | |
-------------------------------------------------------------------------------------------------------------------------------- | |
event's properties for KEYDOWN (this event appropriate for process shortcuts pressed by user) | |
e.altKey - returns true or false | |
e.ctrlKey - returns true or false | |
e.shiftKey - returns true or false | |
e.keyCode - returns code of pressed button (code of keyboard's button) | |
event's properties for KEYPRESS (this event is appropriate for getting symbols entered by user) | |
e.altKey - returns true or false | |
e.ctrlKey - returns true or false | |
e.shiftKey - returns true or false | |
e.charCode - returns code of pressed button (code of symbol) | |
-------------------------------------------------------------------------------------------------------------------------------- | |
String.fromCharCode() - turns code of pressed button to string format | |
e.charCode - property on event object for event 'keypress', gets code of pressed button on keyboard | |
String.formCharCode(e.charCode) - returns string of code that equals pressed keyboard button | |
-------------------------------------------------------------------------------------------------------------------------------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment