The method of Div+css layout Web page to realize multi-style selection

Source: Internet
Author: User
Tags date return window
css| Page | page 1. Styleswitcher.js
function Setactivestylesheet (title) {
var i, a, main;
for (i=0; (A = document.getElementsByTagName ("link") [i]); i++) {
if (A.getattribute ("rel"). IndexOf ("style")!=-1 && a.getattribute ("title") {
A.disabled = true;
if (A.getattribute ("title") = = A.disabled = false;
}
}
}

function Getactivestylesheet () {
var i, A;
for (i=0; (A = document.getElementsByTagName ("link") [i]); i++) {
if (A.getattribute ("rel"). IndexOf ("style")!=-1 && a.getattribute ("title") &&!a.disabled) return A.getattribute ("title");
}
return null;
}

function Getpreferredstylesheet () {
var i, A;
for (i=0; (A = document.getElementsByTagName ("link") [i]); i++) {
if (A.getattribute ("rel"). IndexOf ("style")!=-1
&& A.getattribute ("rel"). IndexOf ("alt") = = 1
&& A.getattribute ("title")
) return A.getattribute ("title");
}
return null;
}

function Createcookie (name,value,days) {
if (days) {
var date = new Date ();
Date.settime (Date.gettime () + (days*24*60*60*1000));
var expires = "; Expires= "+date.togmtstring ();
}
else expires = "";
Document.cookie = name+ "=" +value+expires+ "; path=/";
}

function Readcookie (name) {
var Nameeq = name + "=";
var ca = Document.cookie.split (';');
for (Var i=0;i < ca.length;i++) {
var c = Ca[i];
while (C.charat (0) = = ') c = c.substring (1,c.length);
if (C.indexof (nameeq) = = 0) return c.substring (nameeq.length,c.length);
}
return null;
}

Window.onload = function (e) {
var cookie = Readcookie ("style");
var title = cookie? Cookie:getpreferredstylesheet ();
Setactivestylesheet (title);
}

Window.onunload = function (e) {
var title = Getactivestylesheet ();
Createcookie ("style", title, 365);
}

var cookie = Readcookie ("style");
var title = cookie? Cookie:getpreferredstylesheet ();
Setactivestylesheet (title);

2, CSS calls:

CODE:
//Default style this call
//other styles such calls

...

3, JS call:

CODE:


4, the realization of the choice of style:
Written in the body of the page

CODE:
> Default Style
> Style one
> Style two

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.