The third lesson is finally with you. Everyone would like to thank Actions for their hard work. Make good use of the resources and tutorials provided by the forum. I hope everyone can learn and improve together: D
If you have any comments, suggestions or ideas, you can go to Post your suggestions or comments in the tutorial Q&A area of this version or the site management version, and we will give you feedback in time :)
The following are the key points of today’s learning:
A. Supplement the variable content in class
B.Basic syntax of if statement
Basic usage of C.window.com()
A. Variables
1. Type rules of variables
Java script is untyped, and its Variables can hold values of any data type.
2. Declaration of variables
In a javascript program, you must declare a variable before using it. Variables are declared using the keyword var. In fact, it is not necessary to declare the variable first. In some cases, variable declaration is optional.
var i;
var sum;
You can also use a var keyword to declare multiple variables;
var i, sum;
You can also bind variable declaration and variable initialization in Together:
var message = 'hello';
var i = 0, j=0, k=0;
Variables declared by var are permanent, because browsers vary whether globals can be removed The attitudes of variables are different, (local variables can all be deleted) for safety, it is best to assume that global variables cannot be deleted.
You can use var to declare the same variable multiple times
When you assign a value to an undeclared variable, js will automatically use which variable to create a global variable for you.
If you want to create a local variable inside a function. Then it must be declared inside the function using var.
3. Scope of variables
If local variables and global variables have the same name, the local variable takes precedence. js does not have block level scope. All variables declared in a function have the same scope.
var x; //Declare an unassigned variable, its value is undefined.
alert(u); //Using undeclared variables will throw an error.
u=3; //Assigning a value to an undeclared variable will create the variable.
4. Primitive type and reference type
var a=3.14; //Primary type
var b=a; //Reference type
B.if statement
if (condition)
Statement segment 1
else
Statement segment 2
Function: If the expression is true, execute statement segment 1; otherwise, execute statement segment 2.
Description:
if -else statement is the most basic control statement in JavaScript, through which the execution order of statements can be changed.
Relational statements must be used in expressions to implement judgment, and they are evaluated as a Boolean value.
It converts zero and non-zero numbers into false and true respectively.
If the statement after if has multiple lines, it must be enclosed in curly braces.
Example
if (age alert("Children");
else
alert("Adult");
end if
Nesting of if statements
if (Boolean value) statement 1;
else if (Boolean value) statement 2;
else if (Boolean value) statement 3;
else statement 4;
In this case, the Boolean expression at each level will be calculated. If it is true, its corresponding statement will be executed, otherwise the statement after else will be executed.
Usage of C.window.com()
1. Basic syntax
window.open(pageURL,name,parameters)
Where:
pageURL is the sub-window path
name is the child window handle
parameters is the window parameters (each parameter is separated by a comma)
Example:
2. Window parameters
where yes/no can also be used 1/ 0; value is a specific value in pixels.
toolbar=yes,no Whether to display the toolbar
location=yes,no Whether to display the URL bar
directories=yes,no Whether to display the navigation bar
status=yes,no Whether to display the status bar
menubar=yes,no Whether to display the menu
scrollbars=yes,no Whether to display the scroll bar
resizable=yes,no Whether to change the size of the announcement window
copyhistory=yes,no Whether to display the history button
width=value The width of the announcement window
Height=value The height of the announcement window
left=value The upper left vertex of the announcement window is 100 pixels from the left side of the screen
top=value The upper left vertex of the announcement window is 100 pixels from the top of the screen
Example: <script> <BR> <!-- <BR> window.open ('url') //url为一网址,如:http://www.numb1.com(绝对) 或 index.htm相对) <BR> --> <BR> </script><script> <BR><!-- <BR>window.open("00000.html","newwindow", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=500,height=500,left=100,top=100") <BR>//--> <BR></script>