If statement
if (test condition) statement1;else statement2;
Comments
/* Comments ... */
Script level: Variables declared directly in <script></script> are equivalent to global variables and can be accessed directly within each function. The variables of life within the function can only be accessed within the function but not elsewhere, if possible using local variables.
Switch statement
Switch (test data) {case ...: statement; break; ... Default: statement; break;}
For loop
for (initial condition; test; update) { adtion;}
Array var name = new Array ()
Two-bit arrays
var seats = new Array (new Array (5), new Array (5),...);
var showTime = ["12:30", "2:45", "5:00", "8:24"];
While loop
while (test) { action; Update;}
Function:reduce, Reuse, recycle
Function name (args) { body return value;}
Functions are also variables, function names are variable names, function bodies are variable values
function Showseatstatus (seatnum) { alert ("...");} var showseatstatus = function (seatnum) { alert ("...");}; var myshowseatstatus = Showseatstatus;
The above two forms are actually the same, when a function body appears alone without a name, is a so-called literal function (function literal), and functions can be like a variable assignment operation. A variable name such as Myshowseatstatus can be used directly when calling a function, so the function name can also be used as a function reference (functions Reference).
One way to call a function in a Web page is in HTML, such as <body onload = "initseats ();" Another method is to write directly in the JS file, such as Window.onload = Initseats; The onload event is a property of the Window object The second way is that you can separate the HTML from the JS code, without nesting the JS code in the HTML, but at the same time it can make it inconvenient to pass parameters when calling the function. So there's so-called anonymous functions (anonymous function), as follows:
document.getElementById ("..."). onclick = function (evt) { showseatstatus (...);};
Here the EVT is passed an event object, of course, it does not need to pass parameters can also be called, but the parameter passed is not used.
The OnLoad event can be used to bind a number of events in a page, and can serve as an initialization function for many events:
Window.onload = function () { //wire other events ... ... Initseats ();}
Head first JavaScript (four)