Este artículo describe cómo JS usa cookies para establecer estilos. Compártelo para su referencia, como sigue:
var stylesHow = ["BlackGreen", "Purple"]; var path = "/"; var styleswitch = {// set setstylesheet: function (stylename) {var i, a, main; for (i = 0; (a = document.getElementsByTagName ("link") [i]); i ++) {if (a.getAttribute ("rel"). indexOf ("style")! = -1 && a.getAttribute ("title")) {a.disable = true; if (a.getAttribute ("title") == stylename) {a.disable = false; this.setcookie ("estilo", nombre de stylen); }}}}}}}, // Obtenga el estilo actual utilizado getStylesheet: function () {var i, a; for (i = 0; (a = document.getElementsBytagName ("link") [i]); i ++) {if (a.getAttribute ("rel"). indexOf ("style")! = -1 && a.getAttribute ("title") &&! A.disable) {return a.getTribe ("title"); }} return null; }, // Obtenga el estilo predeterminado getPreferRedStylesheet: function () {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")) {regreso a.getAttribute ("Title"); }} return null; }, // getc cookie getcookie: function (name) {var Cookiename = EncodeuriComponent (name) + "=", CookeStart = Document.cookie.indexof (Cookiename), Cookievalue = null; if (CookeStart> -1) {var cookieend = document.cookie.indexof (";", CookeStart); if (CookeStart == -1) {Alert (-2); cookieend = document.cookie.length; } Cookievalue = DecodeuriComponent (document.cookie.substring (CookeStart + Cookiename.length, Cookieend)); } para (var i = 0; i <styleshow.length; i ++) {if (cookievalue == styleshow [i]) {alert (styleshow [i]); return Styleshow [i]; }} return Styleshow [0]; }, // Generar cookie // nombre Nombre de la cookie // valor de valor // expira el tiempo de caducidad // ruta de ruta setcookie: function (nombre, valor, expiras, ruta, dominio, seguro) {var Cookietext = CododeuriCoponent (name) + "=" + CodeuricOpont (valor) + ";"; if (expirate instanceOf date) {Cookietext + = "expires =" + expires.togmtString (); } if (ruta) {Cookietext + = "; Path =" + Path; } if (dominio) {Cookietext + = "; Domain =" + Domain; } if (seguro) {Cookietext += "; Secure"; } document.cookie = Cookietext; }, // Restablecer cookie unsetcookie: función (nombre, ruta, dominio, seguro) {this.set (nombre, "", nueva fecha (0), ruta, dominio, pantalla); }};Para obtener más información sobre el contenido relacionado con JavaScript, consulte los temas de este sitio: "Resumen de las técnicas de operación JSON en JavaScript", "Resumen de JavaScript Switching Effects and Techniques", "Resumen de JavaScript Algorithm Techniques", "Resumen de efectos de animación de JavaScript y técnicas", ",", ",", ",", ",", ",", ",", ",", ",", ",", ",", ",", ",", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", Estructuras de datos y técnicas de algoritmo "," Resumen de los algoritmos y técnicas transversales de JavaScript "y" Resumen del uso de operaciones matemáticas de JavaScript "
Espero que este artículo sea útil para la programación de JavaScript de todos.