为了账号安全,请及时绑定邮箱和手机立即绑定

HTML5怎样推迟一个函数的执行?

HTML5怎样推迟一个函数的执行?

HUWWW 2019-02-26 11:07:57
<html>function a() { alert("aa"); }function b(){ a(); }<body onloud="b()"></body></html>退出a()函数的执行!
查看完整描述

4 回答

?
慕容3067478

TA贡献1773条经验 获得超3个赞

  1.[self performSelector:@selector(函数名) withObject:nil afterDelay:5.0f]
  条件:在uiviewController的主线程中

  2.[NSTimerscheduledTimerWithTimeInterval:5.0f target:self selector:@selector(函数名) userInfo:nil repeats:NO];
在具体函数中,执行代码,执行完毕以后调用NSTimer invalidate方法来销毁timer
  3.[NSThread sleepForTimeInterval:5.0f];
[要延迟执行的方法];
  条件:主线程或者子线程都可

查看完整回答
反对 回复 2019-03-26
?
犯罪嫌疑人X

TA贡献2080条经验 获得超4个赞

<html>
function a()
{ alert("aa"); }
function b()
{ a(); }
<body onload="window.setTimeout(b,5000);"></body>
</html>

查看完整回答
反对 回复 2019-03-26
?
郎朗坤

TA贡献1921条经验 获得超9个赞

function a()
{ alert("aa"); }
function b()
{ setTimeout(a(),延迟时间); }
<body onloud="b()"></body>

查看完整回答
反对 回复 2019-03-26
?
一只萌萌小番薯

TA贡献1795条经验 获得超7个赞

用async或者是defer这种HTML5新标签可以延迟加载函数

查看完整回答
反对 回复 2019-03-26
  • 4 回答
  • 0 关注
  • 996 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信