the book of javascript 2nd edition phần 2

Sách được chia làm 5 phần rõ ràng gồm: Tổng quan về JavaScript, Sử dụng JavaScript, Hàm và đối tượng, Tạo đối tượng trong JavaScript, Sự kiện trong JavaScript. | writes whatever lies between the parentheses to the web page. Before diving into the date functions that you ll need to write the date to your web page I ll talk about two interesting functions just so you get the hang of how functions work. alert One handy function is alert which puts a string into a little announcement box also called an alert box . Figure 2-7 demonstrates how to call an alert and Figure 2-8 shows what the alert box looks like. html head title An Alert Box title script type text javascript -- hide me from older browsers o alert This page was written by thau show me -- script body h1 To code perchance to function h1 body html Figure 2-7 Creating an alert box The first thing visitors see when they come to the page Figure 2-7 creates is an alert box announcing that I wrote the page Figure 2-8 . The alert box appears because of o which tells JavaScript to execute its alert function. While the alert box is on the screen the browser stops doing any work. Clicking OK in the alert box makes it go away and allows the browser to finish drawing the web page. In this case that means writing the words To code perchance to function Figure 2-8 The alert box to the page . The alert function is useful for troubleshooting when your JavaScript isn t working correctly. Let s say you ve typed in Figure 2-6 but when you run the code you see that you must have made a typo it says there are 0 seconds in a day instead of 86400. You can use alert to find out how the different variables are set before multiplication occurs. The script in Figure 2-9 contains an error that causes the script to say there are undefined seconds in a year and to track down the error I ve added alert function statements that tell you why this problem is occurring. 22 Chopter 2 html head title Seconds in a Day title script type text javascript -- hide me from older browsers var seconds_per_minute 60 var minutes_per_hour 60 o var Hours_per_day 24 alert seconds per minute is seconds_per_minute alert

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
463    21    1    03-12-2024
272    24    1    03-12-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.