In diesem Artikel wird beschrieben, wie JS Cookies verwendet, um Stile festzulegen. Teilen Sie es für Ihre Referenz wie folgt weiter:
var styleshow = ["Blackgreen", "lila"]; var path = "/"; var stylesSwitch = {// Set Style setStylesheet: Funktion (Stylename) {var i, a, main; für (i = 0; (a = document.getElementsByTagName ("link") [i]); i ++) {if (a.getAttribute ("rel"). indexof ("style")! if (a.getAttribute ("title") == styleName) {a.disabled = false; this.setcookie ("style", stylename); }}}}}}}, // den aktuellen verwendeten GetStylesheet: function () {var i, a; für (i = 0; (a = document.GetElementsByTagName ("link") [i]); i ++) {if (a.getAttribute ("rel"). Indexof ("style")! }} return null; }, // Erhalten Sie den Standardstil getPreferredStylheet: function () {var i, a; für (i = 0; (a = document.getElementsByTagName ("link") [i]); i ++) {if (a.getAttribute ("rel"). Indexof ("style")! }} return null; }, // GetC Cookie getcookie: function (name) {var cookiename = encodeuricomponent (name) + "=", cookiestart = document.cookie.indexof (cookiename), cookievalue = null; if (cookiestart> -1) {var cookieend = document.cookie.indexof (";", cookiestart); if (cookiestart == -1) {alert (-2); Cookieend = document.cookie.length; } cookievalue = decodeuricomponent (document.cookie.substring (cookiestart + cookiename.length, Cookieend)); } für (var i = 0; i <styleshow.length; i ++) {if (CookieWalue == StylesHow [i]) {alert (styleshow [i]); Return StylesHow [i]; }} return stylesHow [0]; }, // Cookie generieren // Name Cookie Name // Wertwert // Ablaufzeit // Pfad Pfad setCookie: Funktion (Name, Wert, Ablauf, Pfad, Domäne, sicher) {var cookietext = cododeuricomponent (Name) + " + + Encodeuricomponent (Wert) +"; if (expires Instance von Datum) {cookietext + = "expires =" + expires.togmtstring (); } if (path) {cookietext + = "; path =" + path; } if (domain) {cookietext + = "; Domain =" + Domain; } if (sicher) {cookietext += "; sicher"; } document.cookie = Cookietxt; }. }};For more information about JavaScript related content, please check out the topics of this site: "Summary of JSON operation techniques in JavaScript", "Summary of JavaScript switching effects and techniques", "Summary of JavaScript search algorithm techniques", "Summary of JavaScript animation effects and techniques", "Summary of JavaScript errors and debugging techniques", "Summary of JavaScript Datenstrukturen und Algorithmus -Techniken "," Zusammenfassung der JavaScript -Traversalalgorithmen und -techniken "und" Zusammenfassung der Verwendung von JavaScript -Mathematikoperationen ""
Ich hoffe, dieser Artikel wird für JavaScript -Programme aller hilfreich sein.