1. The meaning of path symbols
The slash src="/js/", "../" means the absolute path, which means the root directory of the website.
Others such as "./ ", "../", "" , "js/", etc. represent paths relative to the current web page and are relative paths.
2. Get the root directory of the website
function GetRootPath() {
var strFullPath = ;
var strPath = ;
var pos = (strPath);
var prePath = (0, pos);
var postPath = (0, (1).indexOf('/') + 1);
return (prePath + postPath);
}
3. Get the parameters of the url
//The URL of the website is as follows: ?a=12
= function (name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
var r = (("\?") + 1).match(reg);
if (r != null) return unescape(r[2]); return null;
}
var strHref = ;
alert(("a"));
4. Functions in js
4.1 Four-sweeping
((0.60) + "<br />") 1
((0.50) + "<br />") 1
((0.49) + "<br />") 0
((-4.40) + "<br />") -4
((-4.60)) -5
4.2 () Returns a random number between 0 and 1.
(())
((()*11)) The floor() method and random() of the Math object to return a random number between 0 and 10
4.3 Is it a non-number? If it is a non-number, false
4.4 Number() converts the value of the object into a number
4.5 parseFloat() parseInt() Returns NaN if the first character of the string cannot be converted to a number
4.6 The String() function converts the value of an object into a string
5. Array
5.1 Combination of arrays and concats to merge arrays, generates new arrays, and the original array remains unchanged
var arr = new Array(3)//Define array
arr[0] = "George"
arr[1] = "John"
arr[2] = "Thomas"
var arr1 = new Array(3)
arr1[0] = "James"
arr1[1] = "Adrew"
arr1[2] = "Martin"
var arr2=(arr1))
5.2 Combination of string joins. The default is "," to be connected, and can be specified, such as join(".")
6. Regular expressions The most commonly used one is test(), and it is true, otherwise it is false
var patt1=new RegExp("e");
(("The best things in life are free"));
7. Events
7.1 The onload and onUnload pages are loaded and called during unloading
7.2 OnFocus, onBlur, and onChange events are usually used to verify forms
<input type="text" size="30" onchange="checkEmail()">
7.3 onSubmit is used to validate all form fields before submitting a form
/*
Here is an example of using the onSubmit event. The checkForm() function is called when the user clicks the confirm button in the form. If the domain value is invalid, the submission will be cancelled. The return value of the checkForm() function is true or false. If the return value is true, submit the form, otherwise cancel the submission. */
<form method="post" action="" onsubmit="return checkForm()">
8. cookie
8.1 Create
function setCookie(c_name,value,expiredays)
{
var exdate=new Date()
(()+expiredays)
=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+())
}
8.2 Read
function getCookie(c_name)
{
if (>0)
{
c_start=(c_name + "=")
if (c_start!=-1)
{
c_start=c_start + c_name.length+1
c_end=(";",c_start)
if (c_end==-1) c_end=
return unescape((c_start,c_end))
}
}
return ""
}
9. Time
setTimeout() starts timing
var t=setTimeout("javascript statement", milliseconds) clearTimeout(t) //Stop timekeeping
10. Open the website
10.1 Open the website in another window ()
function openW(v){
var str = 'width=200,height=200,left=200,top=200,status=no,scrollbars=no,'
str += 'menubar=no,toolbar=no,resizable=no,location=no'
(v,'',str);
}
10.2 Open the website in the same window
='http://' ;
11. Object
11.1 Object definition, destruction
var oObject = new Object;
// do something with the object here
oObject = null;
11.2 Defining a class
function Cat(name,color){
= name;
= color;
= "Female";
= function(){alert("Eat mouse");};
}
11.3 Using JSON to construct an object
var People = {
Create: function (name, age) {
= name;
= age;
},
SayHello: function () {
alert("Hello,My name is " + + ".I am " + );
}
};
11.4 Using prototype to construct an object
var Person = function (name, age) {
= name;
= age;
};
= function () {
alert("My name is " + + ".I'm " + );
}
The slash src="/js/", "../" means the absolute path, which means the root directory of the website.
Others such as "./ ", "../", "" , "js/", etc. represent paths relative to the current web page and are relative paths.
2. Get the root directory of the website
Copy the codeThe code is as follows:
function GetRootPath() {
var strFullPath = ;
var strPath = ;
var pos = (strPath);
var prePath = (0, pos);
var postPath = (0, (1).indexOf('/') + 1);
return (prePath + postPath);
}
3. Get the parameters of the url
Copy the codeThe code is as follows:
//The URL of the website is as follows: ?a=12
= function (name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
var r = (("\?") + 1).match(reg);
if (r != null) return unescape(r[2]); return null;
}
var strHref = ;
alert(("a"));
4. Functions in js
4.1 Four-sweeping
Copy the codeThe code is as follows:
((0.60) + "<br />") 1
((0.50) + "<br />") 1
((0.49) + "<br />") 0
((-4.40) + "<br />") -4
((-4.60)) -5
4.2 () Returns a random number between 0 and 1.
Copy the codeThe code is as follows:
(())
((()*11)) The floor() method and random() of the Math object to return a random number between 0 and 10
4.3 Is it a non-number? If it is a non-number, false
4.4 Number() converts the value of the object into a number
4.5 parseFloat() parseInt() Returns NaN if the first character of the string cannot be converted to a number
4.6 The String() function converts the value of an object into a string
5. Array
5.1 Combination of arrays and concats to merge arrays, generates new arrays, and the original array remains unchanged
Copy the codeThe code is as follows:
var arr = new Array(3)//Define array
arr[0] = "George"
arr[1] = "John"
arr[2] = "Thomas"
var arr1 = new Array(3)
arr1[0] = "James"
arr1[1] = "Adrew"
arr1[2] = "Martin"
var arr2=(arr1))
5.2 Combination of string joins. The default is "," to be connected, and can be specified, such as join(".")
6. Regular expressions The most commonly used one is test(), and it is true, otherwise it is false
Copy the codeThe code is as follows:
var patt1=new RegExp("e");
(("The best things in life are free"));
7. Events
7.1 The onload and onUnload pages are loaded and called during unloading
7.2 OnFocus, onBlur, and onChange events are usually used to verify forms
<input type="text" size="30" onchange="checkEmail()">
7.3 onSubmit is used to validate all form fields before submitting a form
Copy the codeThe code is as follows:
/*
Here is an example of using the onSubmit event. The checkForm() function is called when the user clicks the confirm button in the form. If the domain value is invalid, the submission will be cancelled. The return value of the checkForm() function is true or false. If the return value is true, submit the form, otherwise cancel the submission. */
<form method="post" action="" onsubmit="return checkForm()">
8. cookie
8.1 Create
Copy the codeThe code is as follows:
function setCookie(c_name,value,expiredays)
{
var exdate=new Date()
(()+expiredays)
=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+())
}
8.2 Read
Copy the codeThe code is as follows:
function getCookie(c_name)
{
if (>0)
{
c_start=(c_name + "=")
if (c_start!=-1)
{
c_start=c_start + c_name.length+1
c_end=(";",c_start)
if (c_end==-1) c_end=
return unescape((c_start,c_end))
}
}
return ""
}
9. Time
setTimeout() starts timing
var t=setTimeout("javascript statement", milliseconds) clearTimeout(t) //Stop timekeeping
10. Open the website
10.1 Open the website in another window ()
Copy the codeThe code is as follows:
function openW(v){
var str = 'width=200,height=200,left=200,top=200,status=no,scrollbars=no,'
str += 'menubar=no,toolbar=no,resizable=no,location=no'
(v,'',str);
}
10.2 Open the website in the same window
='http://' ;
11. Object
11.1 Object definition, destruction
Copy the codeThe code is as follows:
var oObject = new Object;
// do something with the object here
oObject = null;
11.2 Defining a class
Copy the codeThe code is as follows:
function Cat(name,color){
= name;
= color;
= "Female";
= function(){alert("Eat mouse");};
}
11.3 Using JSON to construct an object
Copy the codeThe code is as follows:
var People = {
Create: function (name, age) {
= name;
= age;
},
SayHello: function () {
alert("Hello,My name is " + + ".I am " + );
}
};
11.4 Using prototype to construct an object
Copy the codeThe code is as follows:
var Person = function (name, age) {
= name;
= age;
};
= function () {
alert("My name is " + + ".I'm " + );
}