Recently doing the project in writing JS encountered such a problem: I need to write a similar to the matrix of the effect of the page will continue to have data to show 650) this.width=650; "Src=" http://s3.51cto.com/wyfs02/M00/48/79/ Wkiol1qijunw4ox-aafuw44p4pm345.jpg "title=" qq picture 2222222222222222222.jpg "alt=" Wkiol1qijunw4ox-aafuw44p4pm345.jpg " />
So I thought about the timer function timing (500 milliseconds) on the page row of the data display but I also need to take other data in the background (not a one-time check out) so I want to use the outer nesting of a for loop so that JS will first take out the data timed display and then fetch the second paragraph of data results found JS does not support this The function of using the timer under the type for loop
for (Var i=1;i<10;i++) {setTimeout ("alert (' i= ' +i+" ') ", 100); Alert (i)}
This JS will not be executed in sequence, but will be processed below the following alert () in JS will be 100 milliseconds before the first to give you a for first execution end and then execute settimeout And because the threading problem JavaScript is unable to implement the PHP sleep function (pause a few seconds after the execution) many people have tried to write a JS sleep function but did not have to do so someone came up with some non-conventional way to get the card:
Method One: Set a function to allow the browser to do a hard calculation tens of thousands of times hundreds of thousands of times the browser suspended animation looks just like a pause.
Method Two: Perform timed place read time and then time operation execution time minus read time if exactly equal to delay time to execute
Both methods have a big problem: when the data is very small when the method two can be achieved but when the data is relatively large when the method of the two will cause the browser to die directly
As to how to deal with this problem or need to carefully study the data and process as far as possible in a timer to complete it! There are more ways than questions!
This article is from the "Jiawu notes" blog, so be sure to keep this source http://jiawu.blog.51cto.com/9349234/1548959
JS for loop timer settimeout invalid?