日期:2014-05-17 浏览次数:20889 次
<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>
------解决方案--------------------
<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>