First, JavaScript Introduction
1.JavaScript What the hell is a thing?
It is a scripting language and requires a host file whose host file is an HTML file.
2. What does it have to do with Java ?
There is no direct connection, Java is Sun (has been acquired by Oracle), JavaScript is Netspace (Netscape, has been acquired by AOL), JScript is Microsoft, 90% like JavaScript, some features can only be used on IE.
3. its usage:
There are three blocks in the HTML position:
(1) Inside head
(2) Body inside
(3) After
For insurance purposes, it is generally written after
<script language= "JavaScript" > code must be placed in this area </script>
4. Three common dialog boxes:
Alert ("") warning dialog box, the function is to pop up a warning dialog box.
Confirm ("") determines the dialog box, the function is to pop up a selection of the OK dialog box, after clicking OK, it returns ture, click Cancel to return False, you can use the variable to receive.
Prompt ("Hint text to display"), which pops up a dialog box that allows you to enter content.
Second, JavaScript Grammar
1. Basic data type:
String, Decimal, Integer, DateTime, Boolean, and so on.
2. variables:
are generic type Var, can store other types of values, can be used directly, not defined. But it's customary to define.
Defining variables: var A; All variable definitions are defined by Var and var is a generic mutable type.
var s = "3.14"; var n = parsefloat (s);; s + = 5;
var d = parseint (s);
3. Arrays:
Definition of the array: new Array (); Its length is dynamically variable and can be placed in any type of element.
Assignment of array elements: a[0]=123;a[1]= "Hello"; The index in the element starts at 0.
The value of the array: A[i];
Array properties: A.length; The number and length of array elements.
Method: A.sort ();//array sorting, sorted by the first character of each element. A.reverse (); Flips the array.
4. functions:
Four elements of a function: name, input, return value, processing.
Define functions: Function add (formal parameter) {function body}//function named Add, input as parameter, return value can be var type, or return value.
The function must be called to execute. Call to function: Add (argument).
* can be read on the head (first read the head)
The page is automatically refreshed when the form is submitted, preferably turned off
Writing:
1. Output
<script>
document.write ("HelloWorld");
</script>
2. Button Application
<input name= "alert" value= "alert" type= "button" onclick= ' Alert ("This is the trigger event") '/>
3. Define variables and output
var Bianliang;
Bianliang= "123";
document.write (Bianliang);
4. Changing the attributes of an element
<pid= "Hello" >hello</p>
<script>
function Hello ()
{
X=document.getelementbyid ("Hello")
X.style.color = "#ff0000";
}
</script>
<input type= "button" value= "Click to change Color" onclick= "hello ()"/>
<!--click From Black to red--
5 , Item index, indicating the first N an element that appears, with the Getelementsbyname simultaneous use
Define a set of variables
var student =
{
Name: " Zhang San ",
Sex: " male "
};
student.name= " Zhang San ";
document.write (Student.name);
( * Print " Zhang San " )
External calls JS
<script src= "" ></script>
1. type conversion:
It is divided into automatic conversion and casting, which is generally used for casting.
Other types are converted to integers: parseint ();
Other types convert to decimals: parsefloat ();
Determine if it is a valid number type: IsNaN ();
is a number then returns false, not a number to return ture.
Need to put prompt in isNaN method
2. operators:
Math operator : +-*/% + +-;
relational operators : = =! = >= <= > <;
logical operator :&& | | ! ;
Other operators : + = = *=/=%=? :;
3. statement:
It is generally divided into sequential, branching, and cyclic statements.
( 1 ) Branch Statements if :
if (judging condition)
{
Statements that meet the criteria to be executed
}
Else
{
Statements executed when a condition is not met
}
( 2 ) Loop for statement:
For ( initial condition; cyclic condition; state change )
{
Loop Body
}
(3) Problem type: exhaustive, iterative.
(4) Two keywords: break and continue.
(5) If you want to output the value of a parameter: the value of the output is "+a+" and "+b"
<script>function Visible1 ()
{
$ ("P"). Hide ();
};</script>
$ ("ID1") is equivalent to document.getElementById ("ID1")
The first part of JavaScript