TAILIEUCHUNG - JavaScript Bible, Gold Edition part 88

JavaScript Bible, Gold Edition part 88. This book will bring programmers and non-technical professionals, including casual programmers and scripters, painlessly up to speed on all aspects of mastering JavaScript. Key topics include programming fundamentals, JavaScript language elements and how to use them effectively, and how to easily and efficiently add powerful new functionality to HTML documents and Java applets. | 718 Part III Document Objects Reference Listing 29-2 continued NAME layerButton2 onClick alert Event finally reached Button P FORM BODY LAYER BODY HTML Passing events toward their targets If you capture a particular event type your script may need to perform some limited processing on that event before letting it reach its intended target. For example perhaps you want to do something special if a user clicks an element with the Shift metakey pressed. In that case the function that handles the event at the document level inspects the event s modifiers property to determine if the Shift key was pressed at the time of the event. If the Shift key was not pressed you want the event to continue on its way to the element that the user clicked. To let an event pass through the object hierarchy to its target you use the routeEvent method passing as a parameter the event object being handled in the current function. A routeEvent method does not guarantee that the event will reach its intended destination because another object in between may have event capturing for that event type turned on and will intercept the event. That object too can let the event pass through with its own routeEvent method. Listing 29-3 demonstrates event routing by adding onto the document being built in previous examples. While the clickable button objects are the same additional powers are added to the document and layer function handlers that process events that come their way. For each of these event-capturing objects you have additional checkbox settings to allow or disallow events from passing through after each level has processed them. The default settings for the checkboxes are like the ones in Listing 29-2 where event capture for the click event is set for both the document and layer objects. Clicking any button causes the document object s event handler to process and none other. But if you then enable the checkbox that lets the event continue you find that click events on the .

TỪ KHÓA LIÊN QUAN
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.