Създаден от
DOM Event
).onclick
, oncopy
, onscroll
test your mouse on me
var btnNode = document.querySelector('.test');
var outputNode = document.querySelector('.output');
function clickHandler(){
outputNode.innerHTML += "You have clicked with left mouse button
"
}
See the Pen Example - onclickHandler by Iva Popova (@webdesigncourse) on CodePen.
See the Pen Example - Network Events by Iva Popova (@webdesigncourse) on CodePen.
<tagname eventAttribute = "JavaScript code">
// асоциираме 'onclick' event с P елемента:
click me
// асоциираме 'ondblclick' event с P елемента:
double click me
this
в стойността на ивент атрибут, то в this
имаме обекта, представят съответния елемент.
double click me
function clickHandler( node ){
node.innerHTML = "Bravo, you have clicked!"
}
See the Pen changeImageOnSelectChange_EventAttributesDemo by Iva Popova (@webdesigncourse) on CodePen.
element.addEventListener()
методаelement.addEventListener()
методаaddEventListener()
, разгледан в следващите слайдове.
element.addEventListener(eventName, functionDefinition [, options])
See the Pen Example - addEventListener() method by Iva Popova (@webdesigncourse) on CodePen.
var clickHandler = function() {
console.log('click')
};
// тук ще подадем на addEventListener не нашата функция - clickHandler, а резултата от нея (в случая - undefined), а самата функция clickHandler() ще бъде извикана моментално:
document.body.addEventListener( "click", clickHandler() );
See the Pen simpleEventObjectDemo by Iva Popova (@webdesigncourse) on CodePen.
See the Pen simpleEventPropertiesDemo by Iva Popova (@webdesigncourse) on CodePen.
See the Pen target vs. currentTarget by Iva Popova (@webdesigncourse) on CodePen.
See the Pen Using event.target on parent for child actions by Iva Popova (@webdesigncourse) on CodePen.
See the Pen Untitled by Iva Popova (@webdesigncourse) on CodePen.
These slides are based on
customised version of
framework