<script language="javascript" type="text/javascript"> var ap_name = navigator.appName; var ap_vinfo = navigator.appVersion; var ap_ver = parseFloat(ap_vinfo.substring(0, ap_vinfo.indexOf('('))); var time_start = new Date(); var clock_start = time_start.getTime(); var dl_ok = false; function init() { if (ap_name == "Netscape" && ap_ver >= 3.0) dl_ok = true; return true; } function get_time_spent() { var time_now = new Date(); return ((time_now.getTime() - clock_start) / 1000); } function show_secs() // show the time user spent on the side { var i_total_secs = Math.round(get_time_spent()); var i_secs_spent = i_total_secs % 60; var i_mins_spent = Math.round((i_total_secs - 30) / 60); var s_secs_spent = "" + ((i_secs_spent > 9) ? i_secs_spent : "0" + i_secs_spent); var s_mins_spent = "" + ((i_mins_spent > 9) ? i_mins_spent : "0" + i_mins_spent); document.form1.time_spent.value = s_mins_spent + ":" + s_secs_spent; window.setTimeout('show_secs()', 1000); } window.onload = function() { test(); } var sec = 0; var miu = 0; var hour = 0; function test() { var time = document.getElementById("<%=timeBox.ClientID %>"); if (time.value == "") { sec += 1; if (sec == 60) { miu += 1; sec = 0; } if (miu == 60) { hour += 1; miu = 0; } time.value = hour + ":" + miu + ":" + sec; } else { var ts = time.value.split(':'); sec = parseInt(ts[2]); miu = parseInt(ts[1]); hour = parseInt(ts[0]); sec += 1; if (sec == 60) { miu += 1; sec = 0; } if (miu == 60) { hour += 1; miu = 0; } time.value = hour + ":" + miu + ":" + sec; } window.setTimeout("test()", 1000); } </script>var i_mins_spent = Math.round((i_total_secs - 30) / 60);这里-30是什么意思?如何设置停留时间?
1 回答
已采纳
nadirvishun
TA贡献2条经验 获得超1个赞
因为是round四舍五入吗,如果不-30,那当31时,Math.round(31/60)就等于1了,也就是31秒开始分钟变成1分钟,这明显是不对的,应该是61时变为1分钟,Math.round(61-30/60)=1,这就OK了。这个代码貌似是用来检测网页停留时间的,随便加个form和input,改下代码中的getElemntById()为input的id,就能在input的value值中看到结果了
添加回答
举报
0/150
提交
取消