JavaScript Basics 2

Source: Internet
Author: User

==========================================================================================

True: true, not 0 digits, non-empty string, non-empty object

False: False, numeric zero, empty string, empty object, undefined


==========================================================================================

Json


Cycle:

1. Array for 0--length

2.json for in


==========================================================================================

CSS functions


Arguments---indefinite parameter


function sum () {

var result = 0;

for (var i in arguments) {

Result + = Arguments[i];

}

return result;

}



==========================================================================================

Take non-inline styles

Cannot take compound style----background,border


OBJ.CURRENTSTYLE[ATTR]//ie

getComputedStyle (Obj,false) [attr]//chrome FF


function GetStyle (obj,attr) {

if (Obj.currentstyle) {

return obj.currentstyle[attr];

}else{

Return getComputedStyle (Obj,false) [attr];

}


}


==========================================================================================

Use of arrays


One, add, delete


1. Adding headers

Arr.unshift ();


Trailing add

Arr.push ();



2. Head deletion

Arr.shift ();


Trailing Delete

Arr.pop ();


3. Middle Add, delete

Delete: Splice (beginning, length);

Added: Splice (starting point, 0, Element);

Replace: Splice (starting point, number of elements, element);//delete first, add after


Second, sort, convert


1. Connect

A.concat (b);

A.join ('-');//The elements inside the array are connected with '-'


2. Sorting

    sort ();

        var arr = [123,354,57567,798,90,8,7];         arr.sort (function (i,j) {             /*if (I<J) {                 return -1;             }else if (I>J) {                 return 1;             }else{                return  0;            }*/             return i-j;         });     &nbSp;   window.onload = function () {             alert (arr);        };


JavaScript Basics 2

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.