The Show The event continues to propagate as usual, unless one of its event listeners calls 0 or 1, either of which terminates propagation at once.As noted below, calling 3, without specifying 4 has no effect.
Toggling a checkbox is the default action of clicking on a checkbox. This example demonstrates how to prevent that from happening: JavaScript
HTML
ResultThe following example demonstrates how invalid text input can be stopped from reaching the input field with HTMLThe HTML form below captures user input. Since we're only interested in keystrokes, we're disabling 6 to prevent the browser from filling in the input field with cached values.
CSSWe use a little bit of CSS for the warning box we'll draw when the user presses an invalid key:
JavaScriptAnd here's the JavaScript code that does the job. First, listen for 7 events:
The 8 function, which looks at the pressed key and decides whether to allow it:
The 9 function presents a notification of a problem. It's not an elegant function but does the job for the purposes of this example:
ResultCalling You can use 1 to check if the event is cancelable. Calling preventDefault() for a non-cancelable event has no effect. |