About the use of arrays, objects, constructors wording and events

An array of conventional methods, Push () added on the end element method, beginning unshifi additive element method, pop remove the last element, shift removes the first element, a [i] = value change element in the array to String toString, arr.indexOf It contains an element,

arr.splice (arg1, arg2, [arg3 , arg4]); The first parameter defines the Add / Remove element position , the second parameter should be the number of deleted combine multiple arrays; elements, arr.concat (arr1, arr2) generating a new array ; Sort () to alphabetically sort the array;

reverse () inverted elements of the array;

2 embodiment getting a property value: Person [ 'name']; PERSON.NAME ;

After a good object definition can be modified: person.name = "joney";

You can continue to add value: person.height = 180;

Delete Attribute: delete person.height;

var ars=[21,55,38,99,45,76,56,18,67,88];
// for(i=0;i<ars.length;i++){
     for(j=0;j<ars.length-i;j++){
        if(ars[j]>ars[j+1]){
            var t=ars[j+1];
             ars[j+1]=ars[j];
            ars[j]=t;
         }        console.log(ars);
     
                }
 }

  Are arranged according to the number of columns beginning digital size, the size is not arranged according to the value

constituting the constructor function,

function Soldier(name,dagger=10){
    this.name = name;
    this.dagger = dagger;
    this.xl = 10;
    this.gj = function(){
        this.dagger--;
        return '剩余匕首'+this.dagger;
    }
    this.fy = function(){
        var i = parseInt(Math.random()*2);
        this.xl -= i;
        return '剩余血量'+this.xl;
    }
}
var zs = new Soldier('zhangsan',12);
var ls = new Soldier('lisi');

Written 4 DOM object lookup elements and changes in element attributes

方法:document.getElementById()、document.getElementsByTagName()、document.getElementsByClassName();

document.getElementById().innerHTML= newhtml;修改HTML

. Document.getElementById () attribute = new value; modify properties

document.getElementById () setAttribute (attr, val);. modify properties

. Document.getElementById () style.property = new style; style change

5 basic wording event properties

document.getElementById(id).onclick = function(){code};

window : a browser window that opens

Event properties: alert (message); alert box;

setInterval (function () {}, 1000) a timer;

clearInterval () cancel the timer;

setTimeout(function(){},1000);

the clearTimeout (); timer canceled;

Guess you like

Origin www.cnblogs.com/mmore123/p/12045234.html