この記事では、JSがCookieを使用してスタイルを設定する方法について説明します。次のように、参照のために共有してください。
var styleshow = ["blackgreen"、 "purple"]; var path = "/"; var styleswitch = {// set style setstylesheet:function(stylename){var i、a、main; for(i = 0;(a = document.getElementsByTagname( "link")[i]); i ++){if(a.getAttribute( "rel")。 if(a.getattribute( "title")== stylename){a.disabled = false; this.setcookie( "style"、stylename); }}}}}}}}、//現在のスタイルを使用しているGetStylesheet:function(){var i、a; for(i = 0;(a = document.getElementsByTagname( "link")[i]); i ++){if(a.getAttribute( "rel")。 }} nullを返します。 }、//デフォルトのスタイルを取得しますgetPreferredStylesheet:function(){var i、a; for(i = 0;(a = document.getElementsByTagname( "link")[i]); i ++){if(a.getAttribute( "rel")。 }} 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( ";"、cositiestart); if(cocitiestart == -1){alert(-2); cookieend = document.cookie.length; } cookievalue = decodeuricomponent(document.cookie.substring(cookiestart + cookiename.length、cookieend)); } for(var i = 0; i <styleshow.length; i ++){if(cookievalue == styleshow [i]){alert(styleshow [i]); Styleshow [i]を返します。 }} return styleshow [0]; }、// cookie // name name cookie name // value value // expires expiry time // path path setcookie:function(name、value、expires、path、domain、secure){var cookietext = encodeuricomponent(name) + "=" + encodeuricomponent(value) + ";"; "; if(expires instanceof date){cookietext + = "expires =" + expires.togmtstring(); } if(path){cookietext + = "; path =" + path; } if(domain){cookietext + = "; domain =" + domain; } if(secure){cookietext += "; secure"; } document.cookie = cookietext; }、// cookie unsetcookie:function(name、path、domain、secure){this.set(name、 ""、new date(0)、path、domain、screen); }};JavaScript関連のコンテンツの詳細については、このサイトのトピックをご覧ください:「JavaScriptのJSON操作手法の要約」、「JavaScriptの切り替え効果と技術の要約」、「JavaScript検索アルゴリズム技術の要約」、「Javascriptアニメーション効果と技術の要約」、「Javascriptのアニメーション効果と技術の要約」、「Javascript Animation Efters」の概要「要約」、「Javascriptの概要」、「要約」、「要約の要約」データ構造とアルゴリズム手法 "、「javascriptトラバーサルアルゴリズムと手法の要約」および「Javascriptの数学操作の使用法の要約」
この記事がみんなのJavaScriptプログラミングに役立つことを願っています。