基本思路:在body被载入的时候,启动start函数,记录系统此时的时间。当点击按钮的时候,再一次记录系统当前的时间。对两次时间进行求差,得到停留在页面的时间。
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>实验三</title>
<script>
var now,after;
function start()
{
now=new Date();
now.getTime();
}
function end()
{
after=new Date();
after.getTime();
alert("您浏览此网站的时间为:"+((after-now)/1000)+"秒");
}
</script>
</head>
<body onLoad="start()">
<button name="点击" id="b1" onClick="end()">点击</button>
</body>
</html>
0