Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
424 views
in Technique[技术] by (71.8m points)

javascript - JavaScript中是否有睡眠/暂停/等待功能? [重复](Is there a Sleep/Pause/Wait function in JavaScript? [duplicate])

Possible Duplicate:(可能重复:)

Is there a JavaScript function that simulates the operation of the sleep function in PHP — a function that pauses code execution for x milliseconds, and then resumes where it left off?(是否有一个JavaScript函数模拟PHP中sleep函数的操作 - 一个暂停代码执行x毫秒的函数,然后从它停止的地方恢复?)

I found some things here on Stack Overflow, but nothing useful.(我在Stack Overflow上找到了一些东西,但没什么用处。)   ask by Richard translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You need to re-factor the code into pieces.(您需要将代码重新分解为多个部分。)

This doesn't stop execution, it just puts a delay in between the parts.(这不会停止执行,只会在各部分之间造成延迟。) function partA() { ... window.setTimeout(partB,1000); } function partB() { ... }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...