JavaScript: The Definitive Guide, Sixth Editio javaScript权威指南(第6版) pdf 文字版-文字版, javascript电子书, 和javascript 有关的电子书:

17.3.4 Handler Return Value

On the other hand, the modified scope chain of HTML event handlers is a source of pitfalls, since the properties of each of the objects in the chain shadow any properties of the same name in the global object. The Document object defines a (rarely used) open() method, for example, so an HTML event handler that wants to invoke the open() method of the Window object must explicitly write window.open instead of open. There is a similar (but more pernicious) problem with forms, because the names and IDs of form elements define properties on the containing form element (see §15.9.1 ). So if a form contains an element with the ID “location”, for example, all HTML event handlers within that form must use window.location instead of location if they want to refer to the window’s Location object.


17.3.4 Handler Return Value

The return value of an event handler registered by setting an object property or an HTML attribute is sometimes significant. In general, a return value of false tells the browser that it should not perform the default action associated with the event. The onclick handler of a Submit button in a form, for example, can return false to prevent the browser from submitting the form. (This is useful if the user’s input fails client-side validation.) Similarly, an onkeypresshandler on an input field can filter keyboard input by returning false if the user types an inappropriate character. ( Example 17-6 filters keyboard input in this way.)

The return value of the onbeforeunloadhandler of the Window object is also significant. This event is triggered when the browser is about to navigate to a new page. If this event handler returns a string, it will be displayed in a modal dialog box that asks the user to confirm that she wants to leave the page.

欢迎转载,转载请注明来自一手册:http://yishouce.com/book/1/27979.html
友情链接It题库(ittiku.com)| 版权归yishouce.com所有| 友链等可联系 admin#yishouce.com|粤ICP备16001685号-1