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);
   }
}

更新於: 16-Jun-2020

100 次瀏覽

開啟你的 職業生涯

完成課程以獲取認證

開始
廣告
© . All rights reserved.