1, the basic structure of the script is as follows:
<script language= "JavaScript" > <!--javascript statements;-->
Tip: You typically place core script statements between tags
The document.write () method is used for page output display information.
Question: Why does the browser display the contents of the script rather than the results of the script execution?
A, omission start or end of <script>. b, the extension is not. html or. htm. C, the browser does not support JS script.
2, the principle of implementation:
Client requests a page with JavaScript
Download pages with javascript from the server side
Client-side parsing of HTML tags and JavaScript scripts
3. Basic syntax:
var a valid variable name;
Variable names cannot use keywords. Multiple variables can be separated by commas.
The operation symbol is the same as in Java
if (expression) {}else{}
for (initialize; condition; increment or decrement) {}
while (condition) {}
switch (expression)
{Case constant value 1:javascript statement;
Case constant Value 2:javascript statement;
Default:javascript statement;
}
Type: Number/null/boolean/string/object/undefinde
Type conversions: Mastering the Parsefloat () and parseint () functions.
Focus on defining functions: Function function name (argument list) {}
Note: You can also have no parameters
Call Function: Event name = "function name ()"
Get form data: document. Table sole name. form element name. value
Example 1:function Calcu () {
var Numb1=document.calc.num1.value;
var Numb2=document.calc.num2.value;
var total=parsefloat (NUMB1) *parsefloat (NUMB2);
Document.calc.result.value=total; }
<form name= "Calc" >
<input name= "Result" type= "text" size= ">"
<input name= "getanswer" type= "button" id= "Getanswer" onclick= "CALCU ()" >
</form>
Example 2: Print the inverted pyramid line
var i = 25;
while (i>0) {
Docment.write ("
i=i-5;
}
for (Var j=5;j<30;j=j+5) {
Docment.write ("When defining functions, note:
Formal parameters: The parameters defined for a function when the function is defined, which represents the type and location of the parameter.
Actual parameter: The parameter value passed to the function when the function is called.
When called: passes the value of the argument to the parameter.
Function names are strictly case-sensitive.
Multiple parameters are separated by commas, and you must specify a type-compatible value for each parameter separated by commas when you want to invoke the function.
If you need to return a result, use the return statement.
Basic syntax for JavaScript