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

Source: Internet
Author: User

h5edu  Tutorial, Main introduction: JavaScript Intensive tutorial  -- style, Currentstyle, getComputedStyle differences Introduction

Style, Currentstyle, getcomputedstyle differences introduced the stylesheet has three ways inline style (Inline style)  : is written in tag, the inline style is only valid for all tags. Internal style (Internal style sheet): is written in the inside of the HTML, the internal style is only valid for the page on which 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 ( The CSS file is referenced in the Web page of Styles.   Most commonly used is the style property, in JavaScript, by 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 currentstyle,runtimestyle,getcomputedstyle style  standard style, 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 !   Through 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, we need to getcomputedstyle . Note:  getcomputedstyle is in Firefox,  currentstyle is in IE .  such as <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);} The 12document.defaultview.getcomputedstyle (Mydiv,null) can also be obtained under FF in the following way. Width;window.getcomputedstyle (mydiv  , null). Width;


This article is from the "11721999" blog, please be sure to keep this source http://11731999.blog.51cto.com/11721999/1851846

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.