Hızlı yanıt: kod örneği
The W3C Document Object Model Events Specification in 1.3.1. Event registration interfaces states that in the EventListener has no return value:
This method is called whenever an event occurs of the type
for which the EventListener interface was registered. [...] No Return
Valueunder 1.2.4. Event Cancelation the document also states that Cancelation is accomplished by calling the Event's preventDefault
method. If one or more EventListeners call preventDefault during any
phase of event flow the default action will be canceled.which should discourage you from using any effect that returning true / false could have in any browser and use . UpdateThe HTML5 spec actually specifies how to treat a return value different. Section 7.1.5.1 of the HTML Spec states that If return value is a WebIDL boolean false value, then cancel the
event.for everything but the "mouseover" event. ConclusionI would still recommend to use in most projects since you will be compatible with the old spec and thus older browsers. Only if you only need to support cutting edge browsers, returning false to cancel is okay.
handleEvent
handleEvent
event.preventDefault()
event.preventDefault()