The Knowledge collation of JS Foundation

Source: Internet
Author: User
Tags tag name

First, the Operation style:

. Style Action Inline style

. className Modify Class

Second, Operation Properties

1.. Simpler, manipulating existing properties

2. [] More flexible, point can do, square brackets can do. A string is placed in square brackets, the square brackets can be placed in a variable, and a point cannot.

Third, the way to get the elements

document.getElementById get an element by ID

Obj.getelementsbytagname get a set of elements by tag name

Obj.getelementsbyclassname gets an incompatible set of elements through class through class. Incompatible: ie6,7,8

Iv. detection data type: typeof data type: Number Numeric Boolean Boolean value string string undefined undefined object function

V. Get non-inline styles:

function GetStyle (obj,sname) {

Return Obj.currentstyle?obj.currentstyle[sname]:getcomputedstyle (Obj,false) [SName];

}

Six, get random number math.random () get 0-1 decimal between, including 0, never include 1

function rnd (n,m) {

Return parseint (N+math.random () * (m-n));

}

Seven, Timer:

The event is measured in milliseconds

SetInterval (fn,ms) Continuous execution

SetTimeout (FN,MS) executes once

* * First clear and then open.

Viii. Date Object

var odate = new Date (); Get

Odate.getfullyear () Get year

Odate.getmonth () Gets the month, to +1

Odate.getdate () Get Day

Odate.getday () Gets the week, Sunday is 0

Odate.gethours () when acquired

Odate.getminutes () Get points

Odate.getseconds () Get seconds

Odate.gettime (0 get timestamp timestamp: January 1, 1970 0:0:0:0 to the number of milliseconds now experienced

Set Odate.setfullyear (Y,M,D); Odate.setfullyear (Y,M); Odate.setfullyear (y);

Odate.setmonth (M,D); Month to-1 odate.setmonth (m);

Odate.setdate (d); Set Day

Odate.sethours (H,M,S,MS); Odate.sethours (h,m,s); Odate.sethours (H,M); Odate.sethours (h);

Odate.setminutes (M,S,MS); Odate.setminutes (m,s); Odate.setminutes (m);

Odate.setseconds (S,MS); Odate.setseconds (s);

Date objects will carry their own

The array of arguments argument parameters.

When the number of arguments is not fixed, use this thing.

Problems of the Ten and I

1. Add event in loop, use I in Event

FIX: Custom attribute enclosing space

2. Loop add timer, use I in timer

Solution: Closed Space

Xi. closed Space: Save a name. (function () {}) ();

The role of closed spaces: 1. Solve the problem of I. 2. Resolve the problem of variable name conflicts.

12. Eval to turn a string into an executable statement

Brackets are needed when evaljson.

var str = ' {a:1,b:2} ';

Eval (' (' +str+ ') ');

13, the JSON loaded things

No length subscript is name with for...in loop

14. Batch Set style

function SetStyle () {

if (arguments.length==2) {

for (var name in arguments[1]) {

Arguments[0].style[name]=arguments[1][name];

}

}else{

ARUGMENTS[0].STYLE[ARGUMENTS[1]]=ARGUMENTS[2];

}

}

The length of the array can be changed

Empty array: arr.length=0;

arr = [];

Arr.splice (0,arr.length);

while (arr.length) {arr.pop (); Arr.shift (); }

16. Get Browser Information: window.navigator.userAgent

The Knowledge collation of JS Foundation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.