How to get the standard browser
1 varOdiv = document.getElementById (' div ');2 //get the computed font-size3 varSFs = getComputedStyle (Odiv,NULL). GetPropertyValue (' font-size ');//Recommended Use4 //or5 varSfs= getComputedStyle (Odiv,NULL). FontSize;//not recommended for use6 7 Console.log (sFs);8 9 //Note 1: Because of the different names of CSS properties in different browsers (such as Get float), some browsers are. Cssfloat, some are. stylefloat, in order to avoid browser judgment, use. GetPropertyValue (' Float ') to avoid this problem. Ten //NOTE 2: The values in the. GetPropertyValue () method do not support hump writing, such as FontSize can only be written as GetPropertyValue (' font-size ') One}
IE9 How to obtain the following browsers:
1 var odiv = document.getElementById (' div '); 2 // get the computed font-size 3 var // Recommended Use 4 // or 5 var // not recommended for use 6 7 console.log (sFs)
Encapsulation gets the calculated style method
1 functionGetStyle (node,attr) {2 if(typeofgetComputedStyle! = ' undefined '){3 varValue = getComputedStyle (node,NULL). GetPropertyValue (attr);4 returnattr = = ' opacity '? Value * 100:VALUE;//compatible opacity, if it is opaque, returns an integer for easy calculation5}Else if(typeofNode.currentstyle! = ' undefined '){6 if(attr = = ' opacity ') {//compatible opacity7 returnNumber (Node.currentStyle.getAttribute (' Filter '). Match (/(?: O Pacity[=:]) (\d+)/) [1]);8}Else{9 returnNode.currentStyle.getAttribute (attr);Ten } One } A}
JavaScript gets the calculated style