日期:2014-05-16  浏览次数:20367 次

js新手小问题:如何显示在页面停留时间
源代码如下:
<HTML>
<Head>
<Meta   http-equiv= "content-type "   content= "text/html;   charset=gb2312 ">
<Title> JavaScript计时器 </Title>
<H3> <Font   color= "blue "> 主题:JavaScript计时器 </Font> </H3>
</Head>
<Script   language= "javascript ">
</Script>
<Body   onLoad= "window.setTimeout( 'show_secs() ',1); ">
<Form   name= "fm_Time "   onSubmit= "0 ">
<Font   size=5   color= "red "> <center>   显示您停留的时间 </Center> </Font> <P>
<HR   size=3   color= "blue ">
<Font   size=5   color= "blue "> 现在时间: <P>
<Input   type= "text "   name= "t_spent "   size=7   onFocus= "this.blur() ">
</Form> <BR>
</HTML>

------解决方案--------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN ">
<HTML>
<Head>
<Meta http-equiv= "content-type " content= "text/html; charset=gb2312 ">
<Title> JavaScript计时器 </Title>
<H3> <Font color= "blue "> 主题:JavaScript计时器 </Font> </H3>
</Head>

<Body>
<Form name= "fm_Time " onSubmit= "0 ">
<Font size=5 color= "red "> <center> 显示您停留的时间 </Center> </Font> <P>
<HR size=3 color= "blue ">
现在时间: <P>
<Input type= "text " name= "t_spent " id= "t_spent " size=7>
</Form> <BR>
</HTML>
<Script language= "javascript ">
var time=1;
function show_secs(){
document.getElementById( 't_spent ').value=time+ '秒 ';
time++;
window.setTimeout( 'show_secs() ',1000);
}
show_secs();
</Script>