JS 提示函数未定义
<html><head><title>cookie用户来访时间和次数</title><scripttype="text/javascript">functionstart...
<html>
<head>
<title>cookie 用户来访时间和次数</title>
<script type="text/javascript">
function start1()
{
var text="";
var lasttime=getcookie("time");
var month=new Array("一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月");
var weekday=new Array("星期日","星期一","星期二","星期三","星期四","星期五","星期六");
var today=new Date();
var year=today.getFullYear();
var month1=today.getMonth();
var weekday1=today.getDay();
var date=today.getDate();
var cookietime=year+"年"+month[month1]+date+"日"+weekday[weekday1];
today.setDate()+365;
setcookie("time",cookietime,today);
if(visitorname="")
{
visitorname=prompt("请输入姓名");
setcookie("visitorname",visitorname,today);
document.write(visitorname+"欢迎光临");
}
else
{
text+=visitorname+"您是第"+count()+"次访问本站<br>上次访问时间为:"+lasttime;
document.write(text);
}
}
function count()
{
var now=new Date();
now.setTime(now.getDate()+365);
var visits = getcookie("conter");
if(!visits)
{
visits=1;
}
else
{
visits=parseInt(visits)+1;
}
setcookie("counter",visits,now);
return visits;
}
function getcookie(name)
{
if(document.cookie.length>0)
{
start=document.cookie.indexOf(name+"=");
if(start!=-1)
{
start=start+name.length+1;
end=document.cookie.indexOf(";",start);
if(end==-1)
{
end=document.cookie.length;
}
return decodeURI(document.cookie.substring(start,end));
}
}
return ;
}
function setcookie(name,value,expires,path,domain,secure)
{
var curcookie=name+"="+encodeURI(value)+((expires)?";expires="+expires.toGMTString():"")+((path)?";path="+path:"")+((domain)?+";domain="+domain:"")+((secure)?":secure":"");
document.cookie=curcookie;
}
</script>
</head>
<body onload="start1()">
</body>
</html>
body中start1()总是提示未定义 展开
<head>
<title>cookie 用户来访时间和次数</title>
<script type="text/javascript">
function start1()
{
var text="";
var lasttime=getcookie("time");
var month=new Array("一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月");
var weekday=new Array("星期日","星期一","星期二","星期三","星期四","星期五","星期六");
var today=new Date();
var year=today.getFullYear();
var month1=today.getMonth();
var weekday1=today.getDay();
var date=today.getDate();
var cookietime=year+"年"+month[month1]+date+"日"+weekday[weekday1];
today.setDate()+365;
setcookie("time",cookietime,today);
if(visitorname="")
{
visitorname=prompt("请输入姓名");
setcookie("visitorname",visitorname,today);
document.write(visitorname+"欢迎光临");
}
else
{
text+=visitorname+"您是第"+count()+"次访问本站<br>上次访问时间为:"+lasttime;
document.write(text);
}
}
function count()
{
var now=new Date();
now.setTime(now.getDate()+365);
var visits = getcookie("conter");
if(!visits)
{
visits=1;
}
else
{
visits=parseInt(visits)+1;
}
setcookie("counter",visits,now);
return visits;
}
function getcookie(name)
{
if(document.cookie.length>0)
{
start=document.cookie.indexOf(name+"=");
if(start!=-1)
{
start=start+name.length+1;
end=document.cookie.indexOf(";",start);
if(end==-1)
{
end=document.cookie.length;
}
return decodeURI(document.cookie.substring(start,end));
}
}
return ;
}
function setcookie(name,value,expires,path,domain,secure)
{
var curcookie=name+"="+encodeURI(value)+((expires)?";expires="+expires.toGMTString():"")+((path)?";path="+path:"")+((domain)?+";domain="+domain:"")+((secure)?":secure":"");
document.cookie=curcookie;
}
</script>
</head>
<body onload="start1()">
</body>
</html>
body中start1()总是提示未定义 展开
展开全部
代码错误:
1、你调用setcookie()时,传参3个,忘记path参数,所以。。。
2、setcookie() 方法中,var curcookie=name+"="+encodeURI(value)+((expires)?";expires="+expires.toGMTString():"")+((path)?";path="+path:"")+((domain)?+";domain="+domain:"")+((secure)?":secure":""); 最后 的 “;”,你用的是中文的“;”
1、你调用setcookie()时,传参3个,忘记path参数,所以。。。
2、setcookie() 方法中,var curcookie=name+"="+encodeURI(value)+((expires)?";expires="+expires.toGMTString():"")+((path)?";path="+path:"")+((domain)?+";domain="+domain:"")+((secure)?":secure":""); 最后 的 “;”,你用的是中文的“;”
追问
修改好了,但为什么第一次打开不弹出prompt窗口反而显示else里的内容?
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询