用 JavaScript 以名稱讀取 cookie 的最短函式是什麼?


以下是 JavaScript 中用名稱讀取 cookie 的最佳方法。函式如下 −

function ReadCookie() {
   var allcookies = document.cookie;
   document.write ("All Cookies : " + allcookies );

   // Get all the cookies pairs in an array
   cookiearray = allcookies.split(';');

   // Now take key value pair out of this array
   for(var i = 0; i < cookiearray.length; i++) {
      name = cookiearray[i].split('=')[0];
      value = cookiearray[i].split('=')[1];
      document.write ("Key is : " + name + " and Value is : " + value);
   }
}

更新於:2020 年 6 月 16 日

100 次瀏覽

開啟您的 職業生涯

完成課程獲取認證

開始
廣告
© . All rights reserved.