如何在jQuery中使用 setInterval,setTimeout?
$(document).ready(function(){ $.extend({ show:function(){ alert("ready"); } }); setInterval("$.show()",3000); });方法2. 指定定时执行的函数时不要使用引号和括号。
function show(){ alert("ready"); } setInterval(show,3000);// 注意函数名没有引号和括弧!
setTimeout(表达式,延迟时间); 单位:ms(毫秒);1s=1000ms;setInterval(表达式,交 互时间);单位:ms(毫秒);1s=1000ms;window.setTimeout()在执行时,它从载入后延迟指定的时间去执行一个表达式或者是函数;仅执行一次;和window.clearTimeout一起使用.window.setInterval()在执行时,它从载入页面后每隔指定的时间执行一个表达式或者是函数;(功能类似于递归函数);和window.clearInterval一起使用.
基本用法:
执行一段代码:
var i=0; setTimeout("i+=1;alert(i)",1000);