JavaScript Basics Learning-Piecemeal

Source: Internet
Author: User

1. If the Window object is a regular HTML page, TOPis self var top = document.getElementById (' top '); Top.innerhtml//undefined 2, ev.stoppropagation ();// Block Event bubbling
function (EV) {    // organization event bubbling  function() {    for (var i = 0; i < ali.length; i++) {        var img = ali[i].getelementsbytagname (' img ') [0];         = ' Images/darkstar.png ';    }};
3, var ali_right = aul[1].getelementsbytagname (' li '); Ali_right instanceof Array//false--it is an object, but not an array, so you cannot use the array concatenation method concat object Conversion and splicing of an arrayThe way: For loop
varAUl = document.getElementsByTagName (' ul ');varAli_left = aul[0].getelementsbytagname (' li ');varAli_right = aul[1].getelementsbytagname (' li ');varToconcatarray =function(left, right) {varArrli = [];  for(vari = 0; i < left.length; i++) {Arrli.push (left[i]); }     for(varj = 0; J < Right.length; J + +) {Arrli.push (right[j]); }    returnArrli;};varALi =Toconcatarray (Ali_left, ali_right);//However, if you do not need to exclude other Li in a block, only the target Li, you can directly://var aLi = document.getelementsbytagname (' li ');
4. get viewport size and document size
/*viewport size, some mobile device browser to innerwidth compatibility is not good, need to *document.documentelement.clientwidth or document.body.clientWidth * To be compatible (Document.documentElement.clientWidth is not supported in promiscuous mode). * How to use: GetViewport (). width; */functionGetViewport () {if(Document.compatmode = = "Backcompat") {//browser sniffing, promiscuous mode        return{width:document.body.clientWidth, height:document.body.clientHeight}; } Else {        return{width:document.documentElement.clientWidth, height:document.documentElement.clientHeight    }; }}//get the size of the document (the difference and the viewport), the same way you would get the viewport size abovefunctionGetdocumentport () {if(Document.compatmode = = "Backcompat") {        return{width:document.body.scrollWidth, height:document.body.scrollHeight}; } Else {        return{Width:Math.max (document.documentElement.scrollWidth, Document.documentElement.clientWidth), Height:Math.max (Document.documentElement.scrollHeight, Document.documentElement.clientHeight) }}}
clientheight: Content height +padding height, the Innerheight () method in jquery returns this height.   offsetheight: Content height +padding height + border width, the Outerheight () method in jquery returns this height   Note: Use document.getElementById (' bottom '). style. [Height | width]Dom.style.width this way only the inline properties can be taken.Instead of CSS properties

JavaScript Basics Learning-Piecemeal

Related Article

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.