Previously, I often met words such as classname and csstext, but I don't know how to use them. There are four methods to call a style sheet on a webpage.
The first is the external chain, that is, the form of <LINK rel = "stylesheet" href = "/control/CSS/base.css">;
The second is the input style table, and the third is the declaration in the webpage header, such as Finally, the style is written directly after the object, that is, the form of <Div style = "width: 80%...;">. We also need to start from these aspects by using the script call style.
I. In general, we can change the value of href of the external link style to implement real-time switching of the webpage style, that is, "changing the template style ". At this time, we first need to assign an ID to the target to be changed, as shown in figure
<LINK rel = "stylesheet" type = "text/CSS" id = "CSS" href = "firefox.css"/>
It is easy to call, for example, <span on click = "javascript: Document. getelementbyid ('css '). href = 'ie.css'"> click I to change the style </span>
2. Partial style change: Direct style change, classname change, and csstext change. Note: first, JavaScript is very case sensitive. classname cannot write "N" as "N", and csstext cannot write "T" as "T ", otherwise, the effect cannot be achieved. Second, if you change the classname, declare the class in the style sheet in advance.
Document. getelementbyid ('obj '). style. classname = "..." is incorrectly written!
Can only be written as: Document. getelementbyid ('obj '). classname = "..."
However, if csstext is used, style must be added. The correct syntax is as follows:
Document.getelementbyid('obj').style.css text = "..."
I don't have to talk about changing the direct style. You just need to write it into the specific style, as shown in
Document. getelementbyid ('obj '). style. backgroundcolor = "#003366"
New users often do not know how to write CSS styles in Javascript, and sometimes the requirements are different in different browsers. For example, float is written as stylefloat in IE and cssfloat in Firefox. This requires your accumulation.
This article from: the foot home (www.jb51.net) detailed source reference: http://www.jb51.net/article/5161.htm