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

setTimeout用法
请先看下代码:
ccc.jsp

<%@   page   contentType= "text/html;charset=GBK "%>

<html>
<head>
<script   language= "javascript ">
<!--
        var   v_time_num=3;
        var   ss=v_time_num;

function   lk_Log(){
document.form1.t1.value   =   ss;
if(ss==0   ){
    ss=v_time_num; document.getElementById( "log_iframe ").src= "ddd.jsp "     ; log_iframe.log_form.submit();
}
ss--;
setTimeout( "lk_Log() ",   1000);
}
//-->
</script>
</head>
<body>
<form   name= "form1 "   >
<input   type= "text "   name= "t1 "   value= " "   />
</form>
<iframe   id= "log_iframe "   name= "log_iframe "   src= "ddd.jsp "     style= "display:none "   > </iframe>
</body>
<script> window.onload   =   lk_Log; </script>
</html>


ddd.jsp

<%@   page   contentType= "text/html;charset=GBK "%>
<html>
<head>
</head>
<%
System.out.println( "dddddddddddddddddddddddddddddd ");
out.println( " <script> location.href= 'ccc.jsp '; <script> ");
%>
</html>


我想每次在ccc.jsp页面计时结束后,跳转到ddd.jsp,打印完了再回来,重新开始计时,现在跳到ddd.jsp,没有办法回来继续计时了,请指教下。谢谢!

------解决方案--------------------
用cookie记录时间。。。不懂JSP。。飘过。
------解决方案--------------------
ccc.jsp
<script language= "javascript ">
<!--
var v_time_num=3;
var ss=v_time_num;
var tid=null;
function start(){
tid = setTimeout( "lk_Log() ", 1000);
}
function lk_Log(){
document.form1.t1.value = ss;
if(ss==0 ){
if(tid!=null) clearTimeout(tid);
tid=null;
ss=v_time_num; document.getElementById( "log_iframe ").src= "ddd.jsp " ; log_iframe.log_form.submit();
}
ss--;
}
start();
//-->
</script>


ddd.jsp

<%@ page contentType= "text/html;charset=GBK "%>
<html>
<head>
</head>
<%
System.out.println( "dddddddddddddddddddddddddddddd ");
out.println( " <script defer= 'defer '> parent.start(); <script> ");
%>
</html>