javascript中关于setTimeout()问题
setTimeout("setTimeSinceArriving("+start_time+","+update_time+")",update_time);不清楚这行的...
setTimeout( "setTimeSinceArriving("+start_time+","+update_time+") ",update_time);
不清楚这行的层次结构。setTimeout函数不是应该将javascript语句写在“”之间,并以分号结束么?此行中既无分号双引号又众多,浏览器如何解析?
完整代码如下:
<!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>停留时间</title>
<script type="text/javascript">
function setTimeSinceArriving(start_time,update_time){
if(start_time==0){
start_time=getCurrentMillisecs();
}
var millisecs=getCurrentMillisecs();
var millsecondOnPage=millisecs-start_time;
var secondOnPage=Math.round(millsecondOnPage/1000);
document.timeForm.timeSince.value=secondOnPage;
setTimeout( "setTimeSinceArriving("+start_time+","+update_time+") ",update_time);
}
setTimeout(
function getCurrentMillisecs(){
var now=new Date();
var millisecs=now.getTime();
return millisecs;
}
</script>
</head>
<body onload="setTimeSinceArriving(0,1000)">
<form name="timeForm">
你已经在这里呆了:<input type="text" size=10 name="timeSince" />秒
</body>
</html> 展开
不清楚这行的层次结构。setTimeout函数不是应该将javascript语句写在“”之间,并以分号结束么?此行中既无分号双引号又众多,浏览器如何解析?
完整代码如下:
<!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>停留时间</title>
<script type="text/javascript">
function setTimeSinceArriving(start_time,update_time){
if(start_time==0){
start_time=getCurrentMillisecs();
}
var millisecs=getCurrentMillisecs();
var millsecondOnPage=millisecs-start_time;
var secondOnPage=Math.round(millsecondOnPage/1000);
document.timeForm.timeSince.value=secondOnPage;
setTimeout( "setTimeSinceArriving("+start_time+","+update_time+") ",update_time);
}
setTimeout(
function getCurrentMillisecs(){
var now=new Date();
var millisecs=now.getTime();
return millisecs;
}
</script>
</head>
<body onload="setTimeSinceArriving(0,1000)">
<form name="timeForm">
你已经在这里呆了:<input type="text" size=10 name="timeSince" />秒
</body>
</html> 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询