Step one: Define an ID in the element that connects the style sheet, for example
Copy Code code as follows:
<link href= "1.css" rel= "stylesheet" type= "Text/css" id= "CSS";
The ID I defined is CSS.
The second step: Write a JS function, the code is as follows:
Copy Code code as follows:
<script type= "Text/javascript" >
function Change (a) {
var Css=document.getelementbyid ("CSS");
if (a==1)
Css.setattribute ("href", "1.css");
if (a==2)
Css.setattribute ("href", "2.css");
}
</script>
This function's code can be placed anywhere on the page.
Step three: Add a function trigger event for the connection that changes the page's style sheet, the code reads as follows:
Copy Code code as follows:
<a href= "#" onclick= "Change (1)" >1.css</a>
<a href= "#" onclick= "Change (2)" >2.css</a>
This effect in IE and FF are tested through, I believe that we read after reading because it should be very clear, using this method we can allow viewers to choose their own display style sheet, such as the elderly can choose a larger font style sheet. The two points to note here are:
First, in this example, the name after the function name can not be links or link, if links or link, the style sheet will not be changed, for any reason I am not clear, may be the reserved character of JavaScript.
Second, if you change the style of the entire page, you need to define the body height to 100% in the stylesheet file.