Icon website Http://fontawesome.io/icon
<i class= "fa fa-sort" aria-hidden= "true" ></i>
3.21
Function
anonymous functions
Self-executing function creates a function and executes automatically
(function (ARG) {formal parameter
Console.log (ARG);
}) (1) Arguments
Serialization of String variables
Json.stringify () serialization resolves a string from an object
Json.parse () Parses a JSON object in an inverse-order string
Escape
-encodeURI () escape character in Uri
-decodeURI () characters that are not escaped from the URL
After the data has been escaped, it is saved in a cookie
val = eval (expression)
Time
var d = new Date ()
D.getminutes ()
D.setminutes ()
Scope
The scope is a collection of accessible variables, objects, and functions .
The JavaScript variable life cycle is initialized when it declares.
Local variables are destroyed after the function has finished executing.
Global variables are destroyed after the page is closed.
Take a function as a scope
The scope of the function is created before the function is called.
The scope of a function exists in the scope chain, and is also created before it is called: Find their own first, they did not find a layer, no longer look for the outer layer.
Local variables within a function are declared in advance and are not assigned
function func () {
var xo = ' Hequan ';
function inner () {
Console.log (XO);
}
return inner;
}
var ret = func ()
RET ()
Hequan
function func () {
Console.log (XO);
var xo = "Hequan";
}
Func ()
Undefined
Object oriented
function foo (n) {
This.name=n;
this.sayname = function () {
Console.log (THIS.name)
}
}
var obj1 = new Foo ("HQ")
Obj1.name
Obj1.sayname ()
Prototype:
function Foo (n) {
THIS.name = n;
}
Foo.prototype = {
'sayname':function () {
Console.log (THIS.name)
}
}
Obj1 = new Foo (' we ');
Obj1. Sayname ()
Find
Direct Lookup
var obj = document.getElementById (' I1 ')
Indirect lookup
InnerText text
innerHtml Full Content
Obj.value Get Value
Style actions
. className
. classlist.add. Remove
. style.color
Property manipulation
Obj.setattribute ("attribute", "value")
Create tags and add to HTML
String
insertAdjacentHTML ("BeforeEnd", obj)
How objects are
Document.createelement (' div ')
Submit Form
Document.geelementbyid (' form '). Submit ()
Other
Console.log Output Box
Alert Pop-up box
Confirm the Confirm box returns true False
URL and Refresh
Location.href Get URL
location.href = "url" redirection
Location.reload () Reload
Timer
SetInterval Multiple Timers
Clearinterval Clear Multiple Timers
SetTimeout Single Time Timer
Cleartimeout Clear one-time timer
Event
Onclick,onblur,onfocus
document.getElementById get a label by ID
Document.getelementsbyname get a collection of tags based on the Name property
Document.getelementsbyclassname get a collection of tags based on the class property
document.getElementsByTagName get a collection of tags by tag name
Two ways to bind events:
Direct binding onclick= "XX ()"
Get the DOM object first and then bind
<div id = ' Test ' ><button type= "button" >click me!</button></div>
<script>
var mydiv = document.getElementById (' Test ')
Console.log (MYDIV)
Mydiv.onclick = function () {
Console.log (' Asdw ');
}
</script>
This is the label of the current trigger event
The first method of binding
Onclick= "Chang (This)"
function Chang (self) {
Self-currently clicked label
}
The second way of binding
<input id= ' i1 ' type= ' button ' >
document.getElementById (' I1 '). onclick = function () {
The current clicked label of this generation
}
This article is from the "what-all" blog, please be sure to keep this source http://hequan.blog.51cto.com/5701886/1909384
DAY16 Js+dom