当前位置: 代码迷 >> Java Web开发 >> jsp页面定时提交,但是在操作是不能提交如何实现
  详细解决方案

jsp页面定时提交,但是在操作是不能提交如何实现

热度:3121   发布时间:2013-02-25 21:14:31.0
jsp页面定时提交,但是在操作是不能提交怎么实现
例如 离开页面5分钟后自动提交,怎么实现?

------解决方案--------------------------------------------------------
HTML code
    <script type="text/javascript">        function goPost(){            document.myform.submit();        }        var timer = null;        //设置定时器        function startPost(){                   timer = window.setTimeout("goPost()",5000);              }        function stopPost(){                //当触发停止事件后,停止计时器            window.clearTimeout(timer);                     //同时开始一个新的计时器,新计时器时间结束后,没有操作将执行提交函数           timer = window.setTimeout("goPost()",5000);                  }        //停止事件       window.document.onfocusin=stopPost;      window.document.onkeydown=stopPost;        //页面加载完成时调用startPost()方法       window.addEventListener("load", startPost(), false);     </script>  </head>    <body>    <form action="MyJsp.jsp" name="myform" method="post">        <input type="button"  value="test"/>        <input type="text" id="mtime"/>    </form>  </body>
------解决方案--------------------------------------------------------
HTML code
<script type="text/javascript">        function goPost(){            document.myform.submit();        }        var timer = null;        //设置定时器        function startPost(){                   timer = window.setTimeout("goPost()",5000);              }        function stopPost(){                //当触发停止事件后,停止计时器            window.clearTimeout(timer);                     //同时开始一个新的计时器,新计时器时间结束后,没有操作将执行提交函数           timer = window.setTimeout("goPost()",5000);                  }        //停止事件      window.document.onmousedown=stopPost;      window.document.onkeydown=stopPost;        //页面加载完成时调用startPost()方法       window.addEventListener("load", startPost(), false);     </script>  </head>    <body>    <form action="MyJsp.jsp" name="myform" method="post">        <input type="button"  value="test"/>        <input type="text" id="mtime"/>    </form>  </body></html>
  相关解决方案