通过javascript创建一个cookie,记录第一访问网页的时间。 标题的功能怎么实现,求指教,谢谢! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 存到cookie里的时间,你打算怎么用呢?是取出来存到数据库吗? function getCookie(cName) { var sCookie = document.cookie; if (sCookie.length < 1) return false; else { var ar = sCookie.split(';'); for (var i = 0; i < ar.length; i ++) { var ar_tmp = ar[i].split('='); if (ar_tmp[0] == cName) return ar_tmp[1]; } return false; }}if (!getCookie('firstViewTime')) { var d = new Date(), ar_date = [], ar_time = []; ar_date.push(d.getFullYear()); ar_date.push(d.getMonth() + 1); ar_date.push(d.getDate()); ar_time.push(d.getHours()); ar_time.push(d.getMinutes()); ar_time.push(d.getSeconds()); document.cookie += 'firstViewTime=' + ar_date.join('-') + ' ' + ar_time.join(':');}else alert('首次访问时间:' + getCookie('firstViewTime')); <script type="text/javascript">function init(){ var d=new Date(); var cookie=document.cookie; if(cookie.indexOf("firsttime=")==-1){ document.cookie="firsttime="+d+";max-age=100000000"; }else{ var begin=cookie.indexOf("firsttime="); var end=cookie.indexOf(";",begin); if(end==-1){ end=cookie.length; } cookie=cookie.substring(begin+"firsttime=".length,end); alert(cookie); }}window.onload=init;</script>这样试试 300高分求JS真实源文件 背景图片一直要刷新 新手求专家帮助 输入后显示字的个数问题 问个问题 高手请进,如何给html链接,加上验证功能 实际数组?实际数组?实际数组?实际数组?实际数组?实际数组? 正则 清除 onXXX 事件 js中得小数位得问题,round()的使用 救助:ie 5和ie 6有什么区别。为什么我写的程序在ie 5中会使ie关闭? jquery mouseover 事件的问题 跪求一个基于jsp的车辆租赁系统,谢了 想学习JavaScript编辑,不知道该用什么软件【没分了,抱歉】
var sCookie = document.cookie;
if (sCookie.length < 1) return false;
else {
var ar = sCookie.split(';');
for (var i = 0; i < ar.length; i ++) {
var ar_tmp = ar[i].split('=');
if (ar_tmp[0] == cName) return ar_tmp[1];
}
return false;
}
}
if (!getCookie('firstViewTime')) {
var d = new Date(), ar_date = [], ar_time = [];
ar_date.push(d.getFullYear());
ar_date.push(d.getMonth() + 1);
ar_date.push(d.getDate());
ar_time.push(d.getHours());
ar_time.push(d.getMinutes());
ar_time.push(d.getSeconds());
document.cookie += 'firstViewTime=' + ar_date.join('-') + ' ' + ar_time.join(':');
}
else alert('首次访问时间:' + getCookie('firstViewTime'));
function init(){
var d=new Date();
var cookie=document.cookie;
if(cookie.indexOf("firsttime=")==-1){
document.cookie="firsttime="+d+";max-age=100000000";
}else{
var begin=cookie.indexOf("firsttime=");
var end=cookie.indexOf(";",begin);
if(end==-1){
end=cookie.length;
}
cookie=cookie.substring(begin+"firsttime=".length,end);
alert(cookie);
}
}
window.onload=init;
</script>
这样试试