TAILIEUCHUNG - Học JavaScript qua ví dụ part 76

Thêm một sự kiện Các addEventListener Phương. Mô hình sự kiện W3C thêm addEventListener () phương pháp, trong đó đăng ký một người biết lắng nghe sự kiện duy nhất trên một tài liệu, một cửa sổ, nút một DOM hoặc X (HTML), hoặc một XMLHttpRequest Ajax (xem Chương 18, "Giới thiệu về Ajax (với JSON ) "). | 668 Chapter 15 The W3C DOM and JavaScript Figure Further bubbling stops after a user clicks the link. Event Listeners with the W3C Model Adding an Event The addEventListener Method. The W3C event model adds the addEventLis-tenerO method which registers a single event listener on a document a window a DOM node or X HTML or an Ajax XMLHttpRequest see Chapter 18 An Introduction to Ajax with JSON . This method takes three arguments 1. The event type to listen for mouseover click etc. . 2. A function to be executed when the event is fired. 3. A Boolean called useCapture of true or false to specify the event propagation type true to turn on event capturing and false to turn on event bubbling the most cross-browser-compliant way is false . FORMAT type listener useCapture EXAMPLE var div1 mydiv click sayWelcome false From the Library of Event Listeners with the W3C Model 669 You can register more than one event for a target if the events or capture parameters are different. Now we register another event listener to the same element as follows var divl mydiv click bigFont false click smallFont true So which event takes place first The W3C model does not state which event handler is fired first so we will check in Example . However if multiple identical event listeners are registered on the same target with the same parameters the event listener will only be called once and the duplicate instances discarded. Using this within the Handler. As we have seen in many examples throughout this text the this keyword normally represents a reference to an object passed to a function but the this keyword when used with W3C event handlers is a reference to the HTML element from which the event handler was fired giving you easy access to the element. function changeStyle cc0000 EXAMPLE

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã 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.