以下为写的一段代码 当值为-1的时候就是没有cookie
function getCookie(name) {
var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
if(arr = document.cookie.match(reg))
return unescape(arr[2]);
else
return null;
}
$('#a1').click(function() {
var a = getCookie("phone");
var b = getCookie("password");
var c_start = document.cookie.indexOf("phone");
var d_start = document.cookie.indexOf("password");
console.log(a);console.log(c_start);
if(c_start == -1) {
window.location.href = 'my1.html'
} else {
if(d_start == -1) {
alert("别。。伪造cookie");
window.location.href = 'http://www.gov.cn/zhengce/2014-03/21/content_2643049.htm'
} else {
window.location.href = 'my1.html'
}
}
})