<script type="text/javascript">
$(document).ready(function () {
var maintenanceEndDate = new Date(2018, 4, 2, 19, 0, 0);
if (getCookie('remindMaintenanceAgain') == '') {
setCookie('remindMaintenanceAgain', '1', maintenanceEndDate);
}
alert(getCookie('remindMaintenanceAgain'));
});
function setCookie(cname, cvalue, maintenanceEndDate) {
var expires = "expires=" + maintenanceEndDate;
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}
function getCookie(cname) {
var name = cname + "=";
var ca = document.cookie.split(';');
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
</script>
为什么当Cookie的过期日期时间已设置为2018年5月2日19:00时,上面代码中的alert
仍显示1
?
为什么上面的代码可以从过期的cookie中读取?