JavaScript Tutorial - From Getting Started Waste (3) The basic composition of the JavaScript scripting language is the basic composition of the JavaScript scripting language is programming by control statements, functions, objects, methods, attributes, etc. to implement programming. First, the program control flow in any language, the program control flow is necessary, which makes the entire program reduce confusion, making it performed smoothly in a certain manner. The following is a program control flow structure and statement commonly used by JavaScript: 1. IF condition statement basic format IF (expression) statement segment 1; ...... ELSE segment 2; ..... Function: If the expression is True, execute the sentence segment 1; otherwise the segment segment 2 is executed. Description: The if -else statement is the most basic control statement in JavaScript, which can change the order of execution of the statement. The relationship statement must be used in the expression to implement judgment, which is estimated as a boolean value. It transforms zero and non-zero numbers to false and true. If the statement after IF has multiple lines, you must enclose it using the curneth. Nested IF (Boolean) statement 2; ELSE statement 2; ELSE IF (Boolean) statement 3; ... ELSE statement 4; in this case, Boolean expression Calculated, if it is true, the corresponding statement is executed, otherwise the ELSE is executed. 2, for loop statement basic format for (initialization; condition; increment) statement set; function: Implementation condition cycle, when the condition is established, the statement set is executed, otherwise the cyclic body is jumped out. Description: The initialization parameter tells the beginning of the loop, the initial value of the variable must be given; the condition: is used to discriminate the condition of the loop stop. If the condition is met, the cyclic body is executed, otherwise it is jumped out. Incremental: Main Defining Cyclic Control Variables Changes in what ways during each cycle. Between three main statements, comma separation must be separated. 3, WHILE cycle basic format while (condition) statement set; the statement is the same as the for statement, when the condition is true, repeat the loop, otherwise exits the loop. FOR and WHILE statements are all cyclic statements, using the for statement, which is easier to understand when handling the numbers, and is more compact; while the While cycle is more specifically in complex statements. 4, BREAK and CONTINUE statements are the same as C languages, using the BREAK statement to make the loop from the for or while, Continue enters the next loop in the loop from the FOR or WHILE. Second, the function function provides program designers with a full and convenient ability. When a complex program is designed, the program is always divided into some relatively independent portions based on the functionality to be completed, and one function is written. Thus, each part is fully independent, the task is single, clear, easy to understand, easy to read, and easy to maintain. The JavaScript function can encapsulate modules that may be used multiple times in the program. And can be called as an event-driven result. Thus, a function is implemented to associate it with the event driver. This is a place with other languages. 1. JavaScript function defines the function function name (parameter, variation) {function body; .return expression;} Description: When the call function is called, the variable or forma amount can be transmitted as a variable.
The function is defined by the keyword function. Function name: Define the name of its own function. The parameter table is the value passed to the function or action, which can be constant, variables, or other expressions. Call a function by specifying a function name (inform). You must return the value using Return. The function name is sensitive to case. 2, the form parameters in the function: In the definition of the function, we have a parameter table after the function name, which may be one or more. So how can I determine the number of parameter variables? In JavaScript, you can check the number of parameters via arguments .length. Example: 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); ...................................... .. This is different from Java, Java is an object-oriented language. Based on object-based characteristics, event-driven is employed. It is in an environment in which everything is simplified. Usually the action of the mouse or hotkey is called event (Event), and a series of programs caused by the mouse or hotkey, called event driver. For the event, the event is handled or function, we call an event handler (Event Handler). 2. The processing of an event handler in JavaScript is usually served by a function (Function). Its basic format is the same as the function, and all functions described above can be handled as an event handler. The format is as follows: Function event processing name (parameter table) {Event processing statement set; ...} 3, event-driven JavaScript event drives are triggered by the movement of the mouse or hotkey. It mainly has the following events: (1) Click Event OnClick When the user clicks the mouse button, generate an onclick event. At the same time, the event handler or code specified by ONClick will be called executed. Usually produced in the following basic objects: Button, check box, or (check list box) Radio (Single Note) Reset Butt 3 Submit Buttons Example: You can activate the following buttons Change () file: