This article is the official HTML5 training course for h5edu institutions, mainly introduces: JavaScript intensive tutorial--style, Currentstyle, getComputedStyle difference Introduction
Style, Currentstyle, getcomputedstyle differences about the stylesheet there are three ways of inline style (inline style): is written in the tag, the inline style is only valid for all tags. Internal style (internal style Sheet): is written inside the HTML, the internal style is only valid for the page where it resides. External style sheet (External style Sheet): If many Web pages need to use the same style (styles), write the style (styles) in a CSS file with a. css suffix, and then use each of these styles (styles) in each This CSS file is referenced in the Web page. The most common is the style property, in JavaScript, through the document.getElementById (ID). style. XXX can get the value to XXX, but unexpectedly, this can only be taken to the style value set by inline mode, that is, the value set inside the Style property. Solution: Introduce the style of the Currentstyle,runtimestyle,getcomputedstyle style standard, which may be specified by the Style property! Runtimestyle run-time style! If the properties of the style overlap, the properties of the style will be overwritten! Currentstyle refers to the combination of style and Runtimestyle! By Currentstyle, you can get values for CSS styles that are referenced inline or externally (ie only) such as document.getElementById ("test"). Currentstyle.top to be compatible with FF, you have to need to getcomputedstyle. Note: getComputedStyle is in Firefox, Currentstyle is in IE. For example <style> #mydiv {width:300px;} </style>: var mydiv = document.getElementById (' mydiv '); if (Mydiv.currentstyle) {var width = mydiv.currentstyle[ ' Width ']; Alert (' ie: ' + width ');} else if (window.getComputedStyle) {var width = Window.getcomputedstylE (mydiv, null) [' width ']; Alert (' Firefox: ' + width ');} 12document.defaultview.getcomputedstyle (Mydiv,null) can also be obtained under FF in the following way. Width;window.getcomputedstyle (mydiv, NULL ). Width;
This article is the official HTML5 training course for h5edu institutions, mainly introduces: JavaScript intensive tutorial--style, Currentstyle, getComputedStyle difference Introduction
Style, Currentstyle, getcomputedstyle differences about the stylesheet there are three ways of inline style (inline style): is written in the tag, the inline style is only valid for all tags. Internal style (internal style Sheet): is written inside the HTML, the internal style is only valid for the page where it resides. External style sheet (External style Sheet): If many Web pages need to use the same style (styles), write the style (styles) in a CSS file with a. css suffix, and then use each of these styles (styles) in each This CSS file is referenced in the Web page. The most common is the style property, in JavaScript, through the document.getElementById (ID). style. XXX can get the value to XXX, but unexpectedly, this can only be taken to the style value set by inline mode, that is, the value set inside the Style property. Solution: Introduce the style of the Currentstyle,runtimestyle,getcomputedstyle style standard, which may be specified by the Style property! Runtimestyle run-time style! If the properties of the style overlap, the properties of the style will be overwritten! Currentstyle refers to the combination of style and Runtimestyle! By Currentstyle, you can get values for CSS styles that are referenced inline or externally (ie only) such as document.getElementById ("test"). Currentstyle.top to be compatible with FF, you have to need to getcomputedstyle. Note: getComputedStyle is in Firefox, Currentstyle is in IE. For example <style> #mydiv {width:300px;} </style>: var mydiv = document.getElementById (' mydiv '); if (Mydiv.currentstyle) {var width = mydiv.currentstyle[ ' Width ']; Alert (' ie: ' + width ');} else if (window.getComputedStyle) {var width = Window.getcomputedstylE (mydiv, null) [' width ']; Alert (' Firefox: ' + width ');} 12document.defaultview.getcomputedstyle (Mydiv,null) can also be obtained under FF in the following way. Width;window.getcomputedstyle (mydiv, NULL ). Width;
Click to enter JavaScript Intensive tutorial: http://www.h5edu.cn/htm/step/h5edu_44.html
JavaScript Intensive tutorial--style, Currentstyle, getComputedStyle difference Introduction