JS操作Cookie写入和读取实例代码
人气:0
写入cookie实例!
var u = "value=123";
document.cookie = u;
读取cookie实例,读取value的值!
var c_name="value"; // 变量名
if (document.cookie.length > 0) {
c_start = document.cookie.indexOf(c_name + "=")
if (c_start != -1) {
c_start = c_start + c_name.length + 1
c_end = document.cookie.indexOf(";", c_start)
if (c_end == -1) c_end = document.cookie.length
// document.write(document.cookie.substring(c_start,c_end)+"<br>");
var sss= unescape(document.cookie.substring(c_start, c_end)) // 取出值
alert(sss)
}
}
复制代码 代码如下:
var u = "value=123";
document.cookie = u;
读取cookie实例,读取value的值!
复制代码 代码如下:
var c_name="value"; // 变量名
if (document.cookie.length > 0) {
c_start = document.cookie.indexOf(c_name + "=")
if (c_start != -1) {
c_start = c_start + c_name.length + 1
c_end = document.cookie.indexOf(";", c_start)
if (c_end == -1) c_end = document.cookie.length
// document.write(document.cookie.substring(c_start,c_end)+"<br>");
var sss= unescape(document.cookie.substring(c_start, c_end)) // 取出值
alert(sss)
}
}
加载全部内容