在方法里用setTimeout <html> <head> <script type="text/javascript"> function timedMsg() { alert('5 seconds!') var t=setTimeout("timedMsg()",5000) } </script> </head><body> <form> <input type="button" value="Display timed alertbox!" onClick="timedMsg()"> </form> <p>Click on the button above. An alert box will be displayed after 5 seconds.</p> </body></html> 或在外部用setInterval
<html>
<head>
<script type="text/javascript">
function timedMsg()
{
alert('5 seconds!')
var t=setTimeout("timedMsg()",5000)
}
</script>
</head><body>
<form>
<input type="button" value="Display timed alertbox!"
onClick="timedMsg()">
</form>
<p>Click on the button above. An alert box will be
displayed after 5 seconds.</p>
</body></html>
或在外部用setInterval
如果你是固定要5秒一次就用setInterval
setTimeout的副作用是当你JS暂停运行的时候就不会继续执行计时...
自动执行请用onload函数,,,
导入js怎么到html了,用iframe导入html