2

ダウンロードしたスタイルシート スイッチャーが正しく動作しないようです。

スイッチャーは、新しいスタイルシートが読み込まれる限り機能しますが、保存および読み取りを目的とした Cookie は実際には発生しません (ページを更新すると、デフォルトのスタイルシートに戻ると思います)。

Chrome のコンソールは次のエラーを返します。

Uncaught ReferenceError: readCookie が定義されていません

今私の理論では、 readCookie 変数が定義されていないので、それを一番上に移動する必要がありますが、スクリプトが完全に非アクティブになりました。

jQueryに関しては完全な初心者ではありませんが、これはダウンロードされたスクリプトであり、JavaScript Cookieの経験はありません。

どんな助けでも大歓迎です。

(function($)
{
  $(document).ready(function() {
    $('.styleswitch').click(function()
    {
      switchStylestyle(this.getAttribute("rel"));
      return false;
    });
    var c = readCookie('style');
    if (c) switchStylestyle(c);
  });

  function switchStylestyle(styleName)
  {
    $('link[@rel*=style][title]').each(function(i) 
    {
      this.disabled = true;
      if (this.getAttribute('title') == styleName) this.disabled = false;
    });
    createCookie('style', styleName, 365);
  }
})(jQuery);
// cookie functions http://www.quirksmode.org/js/cookies.html
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 var 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;
}
function eraseCookie(name)
{
  createCookie(name,"",-1);
}
4

0 に答える 0