Skip to content

Instantly share code, notes, and snippets.

@precious-ming
Created November 8, 2013 09:29
Show Gist options
  • Save precious-ming/7368561 to your computer and use it in GitHub Desktop.
Save precious-ming/7368561 to your computer and use it in GitHub Desktop.
js延迟加载
<script type="text/javascript">
a();//页面加载执行a()
var i;
function a() {
alert("1");
i = setTimeout("b()", 3000);//3秒后执行b()
}
function b() {
alert("2");
clearTimeout(i); //清除延时代码
//把所有要要延时后执行的代码都写在b()方法里
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment