15.2.5 Event Cancellation
Browsers respond to many user events, even if your code does not: when the user clicks the
mouse on a hyperlink, the browser follows the link. If an HTML text input element has the
keyboard focus and the user types a key, the browser will enter the user's input. If the
user moves their finger across a touch-screen device, the browser scrolls. If you
register an event handler for events like these, you can prevent the browser from
performing its default action by invoking the preventDefault() method of the event
object. (Unless you registered the handler with the passive option, which makes
preventDefault() ineffective.)
Canceling the default action associated with an event is only one kind of event
cancellation. We can also cancel the propagation of events by calling the
stopPropagation() method of the event object. If there are other handlers defined on the
same object, the rest of those handlers will still be invoked, but no event handlers on
any other object will be invoked after stopPropagation() is called. stopPropagation()
works during the capturing phase, at the event target itself, and during the bubbling
phase. stopImmediatePropagation() works like stopPropagation(), but it also prevents the
invocation of any subsequent event handlers registered on the same object.
mouse on a hyperlink, the browser follows the link. If an HTML text input element has the
keyboard focus and the user types a key, the browser will enter the user's input. If the
user moves their finger across a touch-screen device, the browser scrolls. If you
register an event handler for events like these, you can prevent the browser from
performing its default action by invoking the preventDefault() method of the event
object. (Unless you registered the handler with the passive option, which makes
preventDefault() ineffective.)
Canceling the default action associated with an event is only one kind of event
cancellation. We can also cancel the propagation of events by calling the
stopPropagation() method of the event object. If there are other handlers defined on the
same object, the rest of those handlers will still be invoked, but no event handlers on
any other object will be invoked after stopPropagation() is called. stopPropagation()
works during the capturing phase, at the event target itself, and during the bubbling
phase. stopImmediatePropagation() works like stopPropagation(), but it also prevents the
invocation of any subsequent event handlers registered on the same object.
下一篇:沈以诚《我还记得那天》
声明:以上文章均为用户自行添加,仅供打字交流使用,不代表本站观点,本站不承担任何法律责任,特此声明!如果有侵犯到您的权利,请及时联系我们删除。
文章热度:☆☆☆☆☆
文章难度:☆☆☆☆☆
文章质量:☆☆☆☆☆
说明:系统根据文章的热度、难度、质量自动认证,已认证的文章将参与打字排名!
本文打字排名TOP20
登录后可见
用户更多文章推荐
- 15.5.1Document Coordinates and2022-09-02
- 15.2.4 Event Propagation2022-08-30
- 15.2.1 Event Categories2022-08-28
- What JavaScript can't do and2022-08-28
- 13.2 Promises2022-08-27
- Python asyncio About This Book2022-08-27
- Worker Threads2022-08-27
- The Global Object in Workers2022-08-24
- Worker Threads and Messaging2022-08-24
- what's in this book2022-08-07