CSS dynamic loading of the three methods

Related Tags:

  If you have a lot of documents related to the css with loading, or you want to dynamic loading different CSS files, the following methods you have to help you. 

  The first one: general use in the external CSS file must be loaded in the paper 

Code   @ Code import url (style.css); 
  / * Can only be used in the CSS style tags in the document or in the * / 

  The second: a simple loading of the page in an external CSS document 

Code   Code document.createStyleSheet (cssFile); 

  Third: createElement CSS method to create the Link label 

Code   Var head code = document.getElementsByTagName ( 'HEAD'). Item (0); 
  Var style = document.createElement ( 'link'); 
  Style.href = 'style.css'; 
  Style.rel = 'stylesheet'; 
  Style.type = 'text / css'; 
  Head.appendChild (style); 

  I put here in the past several items used in the function, we hope that the useful! 

Code   Code function loadJs (file) ( 
  Var scriptTag = document.getElementById ( 'loadScript'); 
  Var head = document.getElementsByTagName ( 'head'). Item (0); 
  If (scriptTag) head.removeChild (scriptTag); 
  Script = document.createElement ( 'script'); 
  Script.src = ".. / js / mi_" + + file. "Js"; 
  Script.type = 'text / javascript'; 
  Script.id = 'loadScript'; 
  Head.appendChild (script); 
  ) 

  Function loadCss (file) ( 
  Var cssTag = document.getElementById ( 'loadCss'); 
  Var head = document.getElementsByTagName ( 'head'). Item (0); 
  If (cssTag) head.removeChild (cssTag); 
  Css = document.createElement ( 'link'); 
  Css.href = ".. / css / mi_" + + file. "Css"; 
  Css.rel = 'stylesheet'; 
  Css.type = 'text / css'; 
  Css.id = 'loadCss'; 
  Head.appendChild (css); 
  ) 


Related articles:

JScript data type
  Jscript There are three main types of data, two types of data and two special data types.    Main (basic) data type is:    Boolean string numerical composite (quote) data type is:    Object array of special data types are:  Null Undefined   Strin...
Pages on the layout of the interview
  1. Page layout what is your favorite?    Alistair Beattie:    I would not like a separate Web site, others will not.    I would like to judge quality of a web site should be the sole criterion for whether it is useful.    But for the success of this W...
Making learning website: dotted line forms the production method
  In the production of the website, often dotted line forms encountered production problems, the following article will be able to solve this problem.    Method 1: 1 X2 for a plan.    Half black half white, and make use of form lines.    That approach, while tro...
Ajax structural analysis (article sets)
  Ajax structure of the relevant articles 7 Total 2006 Web development trends 05.10.06 read: 30 from IT-man Ajax / Web 2.0. Outline what is fast? Through the following format automatically establish how: html.head.title = "Hello, World. "; html.body.form. @ name =" hello ";...
Cascading Style Sheets (CSS cascading style sheets)
  CSS various attributes    Font attributes    Attribute attribute meaning of attribute values font-family what font to use all of the fonts font-style font whether italics Normal, italic, font oblique font-variant whether capital Normal body, the small-caps font-weight d...