1. Meaning of path symbols
Src ="/The slash JS/jquery. js "," ../"indicates the absolute path, indicating the website root directory.
Others such ". /",".. /"," jquery. JS "," JS/jquery. JS "and so on indicate the paths relative to the current web page and relative paths.
2. Retrieve the root category of the website
FunctionGetrootpath (){
VaRStrfullpath = your own Doc ument. Location. href;
VaRStrpath = too many Doc ument. Location. pathname;
VaRPos = strfullpath. indexof (strpath );
VaRPrepath = strfullpath. substring (0, POS );
VaRPostpath = strpath. substring (0, strpath. substr (1). indexof ('/') + 1 );
Return(Prepath + postpath );
}
3. Retrieve the number of URLs
//Web site URL such as: http://www.A.COM? A = 12
String. Prototype. getquery =Function(Name ){
VaRReg =NewRegexp ("(^ | &)" + name + "= ([^ &] *) (& | $ )");
VaRR =This. Substr (This. Indexof ("\? ") + 1). Match (REG );
If(R! =Null)ReturnUnescape (R [2]);Return Null;
}
VaRStrhref = Window. Location. href;
Alert (strhref. getquery (""));
4. Functions in JS
4.1 math. Round
Document. Write (math. Round (0.60) + "<br/>") 1
Document. Write (math. Round (0.50) + "<br/>") 1
Document. Write (math. Round (0.49) + "<br/>") 0
Document. Write (math. Round (-4.40) + "<br/>")-4
Document. Write (math. Round (-4.60)-5
4.2 math. Random () returns a random number between 0 and 1.
Document. Write (math. Random ())
Document. Write (math. Floor (math. Random () * 11) the floor () method and random () of the math object return a random number between 0 and 10.
4.3 whether isnan () is a non-digital word. If it is a non-digital word, true is false.
4.4 Number () converts the object value to a number
4.5 parsefloat () parseint () if the first character of a string cannot be converted to a number, Nan is returned.
4.6 string () function converts the object value to a string
5. Data groups
5.1 data groups join a Data Group Concat to generate a new data group. The original data group remains unchanged.
VaRArr =NewArray (3)//Definition Data Group
Arr [0] = "George"
Arr [1] = "John"
Arr [2] = "Thomas"
VaRArr1 =NewArray (3)
Arr1 [0] = "James"
Arr1 [1] = "Adrew"
Arr1 [2] = "Martin"
VaRArr2 = arr. Concat (arr1 ))
5.2 data is combined into a string join. It is recognized as "," joined, can be specified, such as join (".")
6. Test () is the most common positive expression in a table. If it is true, it is false. Otherwise, it is false.
VaRPatt1 =NewRegexp ("e ");
Document. Write (patt1.test ("the best things in life are free "));
7. Events
7.1 onload and onUnload are added to the primary node, which is used when the primary node is detached.
7.2 onfocus, onblur, and onchange events are usually used together to verify the form
<Input type = "text" size = "30" id = "email" onchange = "checkemail ()">
7.3 onsubmit is used to verify all form fields before submitting a form
/*
The following is an example of using the onsubmit event. When you click the OK button in the form, the checkform () function is called. If the field value is invalid, this submission will be canceled. The Return Value of the checkform () function is true or false. If the return value is true, the form is submitted, and vice versa.*/
<Form method = "Post" Action = "xxx.htm" onsubmit = "Return checkform ()">
8. Cookie
8.1 zhujian
FunctionSetcookie (c_name, value, expiredays)
{
VaRExdate =NewDate ()
Exdate. setdate (exdate. getdate () + expiredays)
Document. Cookie = c_name + "=" + escape (value) +
(Expiredays =Null)? "": "; Expires =" + exdate. togmtstring ())
}
8.2 fetch
FunctionGetcookie (c_name)
{
If(Document. Cookie. length> 0)
{
C_start = Document. Cookie. indexof (c_name + "= ")
If(C_start! =-1)
{
C_start = c_start + c_name.length + 1
C_end = Document. Cookie. indexof (";", c_start)
If(C_end =-1) c_end = Document. Cookie. Length
ReturnUnescape (document. Cookie. substring (c_start, c_end ))
}
}
Return""
}
9. Scheduled time
Start Time of setTimeout ()
VaR T = setTimeout ("javascript statement", millisecond)
Cleartimeout (t) // Stop the time
10. Open a website
10.1 open the website window. open () in another window ()
FunctionOpenw (v ){
VaRSTR = 'width = 200, Height = 200, Left = 200, Top = 200, status = No, scrollbars = No ,'
STR + = 'menubar = No, toolbar = No, resizable = No, location = no'
Window. Open (v, '', STR );
}
10.2 open a website in the same window
Window. Location. href = 'HTTP: // www.sohu.com ';
11. Object
11.1 for image definition, linear regression
VaROobject =NewObject;
//Do something with the object here
Oobject =Null;
11.2 Definition
FunctionCAT (name, color ){
This. Name = Name;
This. Color = color;
This. Type = "cat ";
This. Eat =Function() {Alert ("Eat mouse ");};
}
11.3 construct an object using JSON
View code
VaRPeople = {
Create:Function(Name, age ){
This. Name = Name;
This. Age = age;
},
Sayhello:Function(){
Alert ("Hello, my name is" +This. Name + ". I am" +This. Age );
}
};
11.4 construct an object using prototype
VaRPerson =Function(Name, age ){
This. Name = Name;
This. Age = age;
};
Person. Prototype. Introduce =Function(){
Alert ("My name is" +This. Name + ". I'm" +This. Age );
}