Web host server - 792Part IIIDocument Objects ReferencepreventDefault() Returns:Nothing. Compatibility:WinIE-, MacIE-, NN6+,
792Part IIIDocument Objects ReferencepreventDefault() Returns:Nothing. Compatibility:WinIE-, MacIE-, NN6+, Moz1+, Safari1+ While NN6+ continues to honor the original way of preventing default action for an event han- dler (that is, having the last statement of the event handler evaluate to return false), theW3C DOM event model provides a method that lets the cancellation of default action takeplace entirely within a function invoked by an event handler. For example, consider a text boxthat is supposed to allow only numbers to be typed in it. The onkeypressevent handler caninvoke a function that inspects each typed character. If the character is not a numeric charac- ter, it does not reach the text box for display. The following validation function may beinvoked from the onkeypressevent handler of just such a text box: function checkIt(evt) { var charCode = evt.charCode; if (charCode < 48 || charCode > 57) { alert( Please make sure entries are numbers only. ); evt.preventDefault(); } } This way, the errant character won t appear in the text box. Invoking the preventDefault()method in NN6+/Moz/Safari is the equivalent of assigningtrueto event.returnValuein IE5+. Related Items:cancelableproperty. stopPropagation() Returns:Nothing. Compatibility:WinIE-, MacIE-, NN6+, Moz1+, Safari1+ Use the stopPropagation()method to stop events from trickling down or bubbling up fur- ther through the element containment hierarchy. A statement in the event listener functionthat invokesevt.stopPropagation(); is all that is needed. As an alternative, you can cancel bubbling directly in an element s eventhandler attribute, as in the following: onclick= doButtonClick(this); event.stopPropagation() If you are writing cross-browser scripts, you also have the option of using the cancelBubbleproperty, which is compatible with IE4+. Related Items:bubbles, cancelBubbleproperties. … (NN6/Moz/Safari) eventObject.preventDefault()
Go visit our java server pages services for a reliable, lowcost webhost to satisfy all your needs.