js封装cookie
Posted sunnywindycloudy
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了js封装cookie相关的知识,希望对你有一定的参考价值。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <title>封装cookie</title> <script> function setCookie(name,value,iDay){ var oDate=new Date(); oDate.setDate(oDate.getDate()+iDay); document.cookie=name+‘=‘+value+‘;expires=‘+oDate; } function getCookie(name){ var arr=document.cookie.split(‘; ‘); for(var i=0;i<arr.length;i++){ var arr2=arr[i].split(‘=‘); if(arr2[0]==name){ return arr2[1]; } } return ‘‘; } function removeCookie(name){ setCookie(name,1,-1); } setCookie(‘name‘,‘sdsd‘); alert(getCookie(‘name‘)); removeCookie(‘name‘); </script> </head> <body> </body> </html>
以上是关于js封装cookie的主要内容,如果未能解决你的问题,请参考以下文章