setTimeout 和 setInterval 的区别

来源:互联网 发布:优衣库中国销售数据 编辑:程序博客网 时间:2024/05/27 21:01

setTimeout() 只执行 code 一次。如果要多次调用,请使用 setInterval() 或者让 code 自身再次调用 setTimeout()。

<html><head><script type="text/javascript">function timedMsg(){var t=setTimeout("alert('5 seconds!')",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 bedisplayed after 5 seconds.</p></body></html>

0 0
原创粉丝点击