tailieunhanh - Học JavaScript qua ví dụ part 55
Các đối tượng sự kiện Như chúng ta đã thấy trong đoạn văn này, các sự kiện đang xảy ra tất cả thời gian với JavaScript. Sự kiện các đối tượng được gửi đến một xử lý sự kiện với mỗi sự kiện xảy ra trong một tài liệu, ví dụ, khi người dùng nhấp vào nút chuột trái, JavaScript đăng ký các sự kiện, những gì quan trọng đã được nhấn | The event Object 499 EXAMPLE continued 1 2 script head body bgcolor white form div align center p image src Image onError alert Image is having trouble loading p input type button value Wake me onClick wakeupCall div form body html EXPLANATION 1 The image tag identifies the src of a .gif image to be loaded from a subdirectory called Image. 2 The onError event handler is triggered when an error occurs while loading the image. See Figure . Figure The onError event handler was triggered because the image src was wrong left and after the image loads right . The event Object As we have seen throughout this text events are happening all the time with JavaScript. Event objects are sent to an event handler with each event that occurs within a document for example when the user clicks on the left mouse button JavaScript registers the event what key was pressed its coordinates pixel positions of where it was pressed on the screen and so on. To learn more about what happened so that you can track problems get pixel coordinates find out what button was pushed or what key was released and so on the event object provides specific information about the event. This topic can be very confusing because W3C Mozilla Firefox type browsers and Microsoft Internet Explorer differ in how events should be handled. Like economists argue over From the Library of 500 Chapter 13 Handling Events taxes trickle-up or trickle-down economics browser companies argued over the order in which events are handled also called event propagation. Does the event bubble up from its target or does it trickle down to its target Capturing and Bubbling Trickle Down and Bubble Up The way that the events are handled differs by the browser and is based on how Netscape and Internet Explorer dealt with events back in the 1990s. Suppose you have used an onClick event handler in the button of a form. The user clicks the button. What happens Netscape said that
đang nạp các trang xem trước