JavaScript Intensive tutorial--style, Currentstyle, getComputedStyle difference Introduction

Source: Internet
Author: User

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

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.