The following functions are all written and can be used directly:
1. The addition and modification of cookies are as follows:
function update(name,val){ document.cookie = name + "=" + val; }
name: represents the key to be saved; val: represents the value to be saved
2. Acquisition of cookies:
function get_cookies(val){ for(var i in document.cookie.split(';')){ if(document.cookie.split(';')[i].split('=')[0] == val){ return document.cookie.split(';')[i].split('=')[1] } } }
val: represents the key you want to get data, such as user='admin', val = user
3. Deletion of cookies:
function delete_cookies(val){ var now_month = new Date(); now_month.setTime(now_month.getTime() - 1); var value = []; for(var i in document.cookie.split(';')){ if(document.cookie.split(';')[i].split('=')[0] == val){ value = document.cookie.split(';')[i].split('=') } } document.cookie = value[0] + "=" + value[1]+ ";expires=" +now_month.toGMTString(); }
val: represents the key you want to get the data;
The above are all separate, you can take what you need.