<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>index</title>
<script type="text/javascript">
var t1=t2=0;
function start(){
var words=document.getElementById("words");
words.value="";
//如果Cookie中不存在用户
if(!Cookie("name")){
var _name=prompt("请输入你的用户名?");
Cookie("name",_name,{expires:360});
}
var date=new Date();
t1=date.getTime();//记录当前时间
words.focus(); //获得焦点
}
function stop(){
var words=document.getElementById("words");
var date=new Date();
t2=date.getTime();//记录暂停时的时间
//计时打字用时
var time=(t2-t1)/(1000*60);
//记录输入的总字数
var num=words.value.length;
//计算打字速度
rate=Math.round(num/time);
//检测Cookie中是否存在历史成绩
Cookie("rate")||Cookie("rate",0,{expires:360});
if(parseInt(Cookie("rate"))<rate){
//如果现在成绩优于历史成绩,则存储该成绩
Cookie("rate",rate,{expires:360});
}
//检测Cookie中的总字数
var sum=Cookie("sum")?Cookie("sum"):0;
//存储累计总字数
Cookie("sum",(parseInt(sum)+num),{expires:360});
var info="你输入的总字数:"+Cookie("sum")+"\n"+
"本次打字数:"+num+"\n"+
"本次打字速度(字/分):"+rate+"\n"+
" 最好成绩:"+Cookie("rate")+"\n";
words.value=info;
}
function clear(){
Cookie("num",null);
Cookie("sum",null);
Cookie("rate",null);
var words=document.getElementById("words");
words.value="";
}
</script>
</head>
<body>
<input type="button" id="start" value="开始测试打字速度" />
<input type="button" id="stop" value="停止" />
<input type="button" id="clear" value="清除Cookie" /><br />
<textarea id="words" cols="80" rows="20"></textarea>
</body>
</html>
为什么没有结果?该怎么改
|