the programming of JavaScript mainly summarizes the following aspects: Control statements, functions, event-driven and event-handling, hoping to help readers a little.
Control statements:
If condition statement
Basic format if (expression) statement segment 1; Else statement segment 2; ..... Function: If the expression is true, the statement segment 1 is executed, otherwise the statement segment 2 is executed.
nesting of If statements
if (Boolean) statement 1; Else (Boolean) statement 2; else if (Boolean) statement 3; Else statement 4; In this case, the Boolean expression for each level is evaluated and, if true, executes its corresponding statement, otherwise the statement after else is executed.
For Loop statement
Basic format for (initialize; conditional; increment) statement set; function: Implement conditional loop, when the condition is set, execute statement set, otherwise jump out of the loop body. Description: The initialization parameter tells the starting position of the loop, the initial value of the variable must be given, and the condition: is used to determine the condition of the loop stop. If the condition is satisfied, the loop body is executed, otherwise it jumps out. Increment: Primarily defines how the loop control variable changes in each loop. Between three main statements, you must use commas to separate them.
While Loop
The basic format while (conditional) statement set, which, like the For statement, repeats the loop when the condition is true, or exits the loop. The for and while statements are circular statements that use the For statement to be more readable and compact when dealing with the numbers, while the while loop is more specific to complex statements.
Break and Continue statements
as with the C + + language, using the break statement causes the loop to jump out of a for or while, continue to skip the remaining statements within the loop and into the next loop.
Function
Functions provide a very convenient ability for program designers. Usually when a complex programming is performed, the program is always divided into relatively independent parts based on the functions to be completed, and each part is written with a function. Thus, the parts are fully independent, the task is single, the procedure is clear, easy to read and easy to maintain. JavaScript functions can encapsulate modules that may be used more than once in a program. A program that can be invoked as an event-driven result. This enables a function to associate it with the event driver. This is a place that is not like other languages.
JavaScript function definitions
Function name (argument, variable) {
function body;.
Return expression;
}
Description:
When a function is called, the variable or literal used can be passed as a variable. Functions are defined by the keyword function. Function Name: Defines the name of your own functions. A parameter table is a value that is passed to or manipulated by a function, whose value can be a constant, variable, or other expression. Invokes a function by specifying a function name (argument). You must return the value using return. The function name is sensitive to capitalization.
formal parameters in a function
In the definition of a function, we see that the function name has a parameter table, which may be one or several variables. So how do you determine the number of parameter variables? In JavaScript, you can pass arguments. Length to check the number of parameters.
Cases:
Function function_name (EXP1,EXP2,EXP3,EXP4) {number =function _name. arguments. Length; if (number>1) document.wrile (EXP2); if (number>2) document.write (EXP3); if (number>3) document.write (EXP4);}
Event-driven and event-handling
JavaScript is an object-based (object-based) language. This differs from Java in that Java is an object-oriented language. The basic feature of object-based is the use of event-driven (Event-driven). It is in the context of the use of the shape interface, so that all input changes to simplify. Usually the action of a mouse or hotkey is called an event, and the action of a sequence of programs triggered by a mouse or hotkey is called event Driver. The event handler or function we call the event Handler
Event handlers
The handling of object events in JavaScript is usually performed by functions. The basic format is the same as the function, and all the functions described earlier can be used as event handlers. The format is as follows: Function event handler name (parameter table) {event handling statement set;.}
Summarize:
for JavaScript, There are several main events: Click event onclick onchange Change events, Select Event Onselect, Get Focus event onfocus, lose focus Onblur, load file onload, Uninstall file onunload and so on. There is a lot of knowledge I have not been contacted and learned, this article, mainly to review and collate the learning and exposure to the knowledge, if there is a mistake welcome point!!
JavaScript's program composition