1. The concept of javaScript: It is a representation language, and it is also a scripting language based on object (Object) and event-driven (EventDriven), which runs on the client, thereby reducing the burden on the server side. The summary is as follows:
1.javaScript is mainly used to find the HTML page to add interactive behavior.
2.javaScript is a scripting language with similar syntax to java.
3. JavaScript is generally used to write client scripts.
4.javaScript is an interpretive language that explains while executing.
2. JavaScript is composed of the core syntax ECMAScript and the browser object model (BOM). It is mainly used to manage communication between windows, so its core object is composed of three parts: window and document object model (DOM).
3. Three ways to introduce javascript to web pages:
1. Use the <Script></Script> tag internal style
2. Use external js files
3. In-line styles directly in HTML tags.
4. The role of javascript
1. Implement page form verification
2. Implement page interaction effects
5. Characteristics of javascript
1. Designed to add interactive behavior to HTML pages
2. It is the most popular scripting language on the Internet
3. Generally used to write client scripts
4. It is an interpretive language
6. How to introduce javascript
1. Use the <Script> tag to embed the web page directly
2. Use external js files
Common methods for String objects in Js:
In javaScript, the conditional statement Switch(){} can be connected to a string;
alert("prompt message");
var isOk=confirm("confirm box");//If confirmation returns true, otherwise return false
prompt();prompt("Prompt information", "Input box default information");
prompt("Please enter your name")
close();
open();
setTimeout(); Call a function after specifying milliseconds
setInterval(); calls a function in milliseconds specified period to milliseconds
window.open();
7.Js syntax:
1. Case sensitive
2. Pay attention to the naming specifications of variables, functions, etc.
3. Each line of code ends with a semicolon
Functions in Js:
1. System functions
ParseInt(); convert to integer 45.9a convert to 45; a6 convert returns to NaN(Not a Number)
isNaN (judging whether it is a number)
typeof(var); determine what data type it is
eval("5+2"); calculates the expression value
2. Custom functions
Function function name(){javaScript code}
Function function name (parameter 1, parameter 2) {javaScript code return return value (optional)}
Calling of functions in Js:
Anonymous functions:
Var variable name = function(parameter){ function body return return value;} ;
Variable name (parameter)
8. Program calls
1. Add alert(); method 2. Use fireBug(); method
9.BOM overview: (Browser Object Model, browser object model)
1. Properties of window object
name | illustrate |
History | Information about URLs visited by the customer |
Location | Information about the current URL |
Screen | Information about the client's screen and display performance |
Common methods for Weindow objects: propt()confirm();setTimeout();setInterval();
Common events for Window objects: onload=”” onmouseover=””;onclick
window.parent.location
2.History object
Method: back() ;forward();go();
3. The Location object provides the URL of the current page
Attribute: host hostname href
Method: reload() replace();
4. Document object
Attribute:referrer attribute determines whether it is accessed through a hyperlink, does not return null
10. Objects in javascript,
Date object:
Create date object and send method var date=new Date(MM DD,YYYY,hh:mm:ss);
var date=new Date(); date.getDay();
Math object:
Ceil(); round up the number, ceil(25.5)=26;
Floor(); round down, floor(25.5)=25;
Math.round(25.5); round down after adding 0.5 to the original number
11.Dom Overview (Document Object Model)
Consisting of CoreDom, XMLDom, HTML Dom;
12. Create an array
Declaration of variables in Js:
Var array name = new Array(size);
Read 1. Read with for loop 2. Read with for---in
For(var x in fruit){document.write(fruit[x]+"<br/>")}x is the subscript
Fruit.sort();//Sort string str=fruit.join("-");//Add string and join into a string
Drop-down Select object:
13. Style positioning style
left top position z-index
Mouse scroll distance: scorllTop: vertical distance
scorllLeft: horizontal distance
Mouse scrolling leave: onscorll
Conversion between Jquery objects and Dom objects
var $txtName=$("#txtName");//jquery object
var txtName=$txtName[0];//Dom object
alert(txtName.checked);//Check whether this checkbox is selected
Get the corresponding Dom object through the get(index) method
Var $txtName=$("#txtName");//jquery object
Var txtName=$txtName.get(0);//Dom object
alert(txtName.checked);//Check whether this checkbox is selected
Var txtName=document.getElementById("txtName");//dom object
Var $txtName=$(txtName);//
Add class attribute in Dom to use obj.className=classname;
Add class content using obj.innerHtml=<input />
Add class attribute in Jquery to use obj.addClaa=classname;
Add class content to use: obj.html=<input/>;
The five major selectors in Jqurey:
Events in Jquery:
Obj.bind("clike",function(){});
obj.bind({mousever:function(){},{mouserout:function(){}}});
obj.unbind();
obj.hover(function(){}, function(){}) method collection onmouseOver and onmouseOut
obj.toggle();
$(".tipsbox").show();obj.hide();
$("img").fadeIn(1000);
$(".txt").slideUp(1000); obj.slideDown(1000);
Obj.toggleClass("class");//Integrate addClass and romoveClass
$(this).val("");//Clear the text content
Var $newNode=$(<"<li>Create new element node with jquery</li>">);
In regular expression
Some common tips in JS:
1. Use the!! operator to convert the boolean value, which can be used for variables! ! Varable for detection. As long as the value of the variable is: 0, null, "" , undefined or NaN will return false and the other way is true
function Account(cash)
{
this.cash = cash;
this.hasMoney = !! cash;
}
2. Use + to convert string to numbers, only string data is applicable, otherwise NaN will be returned
function toNumber(strNum) {
return +strNum;
}
Applicable to Date() Returns the timestamp number: +new Date();
3. When the loop is very large, the length of the number is first given, var legth = array.legth;
4.if('querySelector' in document) {
document.querySelector("#id");
} else {
document.getElementById("id");
}
5. Get the last element in the array
var array = [1,2,3,4,5];
array.slice(-1);
6. Replacement of string elements
var string = "john john";
string.replace(/hn/, "ana"); //"joana john"
string.replace(/hn/g, "ana"); //"joana joana"
The above javaScript knowledge points summary (must-read) is all the content shared by the editor. I hope it can give you a reference and I hope you can support Wulin.com more.