777Chapter 25Event ObjectsIf an event is cancelable, then (Medical web site)
Monday, December 31st, 2007777Chapter 25Event ObjectsIf an event is cancelable, then its default action can be prevented from occurring with thehelp of a script. While most events are cancelable, some are not. The cancelable property letsyou inquire about a particular event object to see if its event type is cancelable. Values forthe property are Booleans. You may want to perform special operations only on events thatare cancelable and handle the others without special treatment. For this branch, you can usethe property in an ifcondition statement: if (evt.cancelable) { // special processing for cancelable events} You do not have to branch, however, just to prevent an event s default action. A non- cancelable event doesn t mind if you tell it to prevent the default action. Related Items:preventDefault()method. cancelBubbleValue:Boolean.Read/WriteCompatibility:WinIE4+, MacIE4+, NN6+, Moz1+, Safari1+ The cancelBubbleproperty is a rare instance of an IE4+ event property being implementedin NN6+/Moz/Safari even though the property is not defined in the W3C DOM. The propertyoperates the same as in IE4+ in that it determines whether the current event object bubblesup any higher in the element containment hierarchy of the document. By default, this prop- erty is false, meaning that if the event is supposed to bubble, it will do so automatically. To prevent event bubbling for the current event, set the property to trueanywhere withinthe event handler function. As an alternative, you can cancel bubbling directly in an element sevent handler attribute, as in the following: onclick= doButtonClick(this); event.cancelBubble = true Cancelling event bubbling works only for the current event. The very next event to fire willhave bubbling enabled (provided the event bubbles). If you are trying to migrate your code as much as possible to the W3C DOM, use thestopPropagation()method instead of cancelBubble. For cross-browser compatibility, however, cancelBubbleis a safe bet. ExampleSee Listing 25-6 to see the cancelBubbleproperty in action in an IE environment. Eventhough that listing has some features that apply to WinIE5.5+, the bubble cancelling demon- stration works all the way back to IE4. Related Items:stopPropagation()method. charCodekeyCodeValue:Integer.Read-OnlyCompatibility:WinIE-, MacIE-, NN6+, Moz1+, Safari1+ The W3C DOM event object model clearly distinguishes between the Unicode characterattached to the alphanumeric keys of the keyboard and the code attached to each of thekeyboard keys (regardless of its character). To inspect the character of a key, use the(NN6/Moz/Safari) eventObject.charCode
In case you need quality webspace to host and run your web applications, try our personal web hosting services.