Học JavaScript qua ví dụ part 33

Tạo sự kiện đặt giờ Phương pháp Timer. Các đối tượng cửa sổ cung cấp hai phương pháp mà hành động như một đồng hồ báo thức để bạn có thể thời gian khi bạn muốn một số điều xảy ra trong chương trình của bạn: setTimeout () và phương thức setInterval () (xem bảng 10,8). Các setTimeout () phương pháp đánh giá một biểu thức sau một khoảng thời gian nhất định và chia tay. Các phương thức setInterval () phương pháp tự động reschedules thực hiện một biểu hiện trong khoảng thời gian thiết lập, tiếp tục lặp lại cho. | 292 Chapter 10 It s the BOM Browser Objects EXPLANATION 1 A new window object is created. If the resizable option is turned off the user will not be able to maximize the window. A maximized window cannot be moved with the moveTo method. 2 The moveTo method determines the position where the window will be moved. The arguments 0 0 represent the x y coordinates column row in pixels. 3 The new window will be put into focus meaning it will be at the top of the window hierarchy in front of all the other windows. 4 The parent window is the original window we started in. It is moved to coordinates 215 x 0 pixels. 5 The parent original window is resized to 400 x 400 pixels. 6 This is the start of a simple HTML form. It creates a simple input device called a button on the screen. 7 This is the onClick event handler. When the user presses the button the event is triggered and a function called directions will be called. The new window is moved to the top left corner and put into focus. See Figure . Figure After moving focusing and resizing both the new window and the parent window Output from Example . Creating Timed Events Timer Methods. The window object provides two methods that act like an alarm clock so that you can time when you want certain things to happen in your program From the Library of JavaScript and the Browser Object Model 293 setTimeout and setInterval see Table . The setTimeout method evaluates an expression after a specified amount of time and quits. The setInterval method automatically reschedules the execution of an expression at set intervals continuing to repeat until the program ends or the setInterval is cancelled. Table Timers Timing Methods What They Do setTimeout Invokes a function or evaluates an expression or a function when the number of milliseconds has passed. setInterval Invokes a function or evaluates an expression or a function at set intervals in milliseconds. Both methods have the same .

Không thể tạo bản xem trước, hãy bấm tải xuống
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
46    110    3    22-05-2024
Đã 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.