SetTimeout "Note: Out of ' o ' is lowercase"
If the function with parameters in settimeout (Function,mill), the defined millisecond tree mill is invalidated and the function method executes immediately
Workaround: Define the parameter as a "global variable", or do not write a method alone, directly in the same method directly write function functions, such as the first settimeout in this example;
Example 1:
var operations =[object Object,object object,object object,object object,object object];function sessionPlayback () { Playcontrol (0);} function Playcontrol (i) {var operation = Operations[i];var content = $ ("#operation_content"). Val (); content+= "#>" + operation.request;$ ("#operation_content"). Val (content); SetTimeout (function () {var content = $ ("#operation_content" ). Val (); content+= operation.response+ "\ r \ n"; $ ("#operation_content"). Val (content);},eval ((Operation.endtime- Operation.starttime) *playspeed)), I ++;if (i<operations.length) {var jiangetime = 0;jiangetime = (Operations[i]. Starttime-operations[i-1].starttime) *playspeed;console.log ("Jiangetime:" +jiangetime); SetTimeout ("PlayControl (" +i+ ")", Jiangetime);}}
Example 2:
function Playcontrol () {Console.log ("operations:" +operations), $ ("#operation_content"). Val (""); for (var i = 0;i < operations.length;i++) {var jiangetime = 0;if (i>0) {jiangetime = Operations[i].starttime-operations[0].starttime;} Console.log ("Jiangetime:" +jiangetime); SetTimeout ("Showoperationhistory (operations[" +i+ "])", jiangetime);} $ ("#operation_content"). focus ();} function Showoperationhistory (operation) {var content = $ ("#operation_content"). Val (); content+= "#>" + operation.request+ "\ r \ n";//Add Line Console.log ("--------------------"); $ ("#operation_content"). Val (content); SetTimeout (function () {var content = $ ("#operation_content"). Val (); content+= operation.response+ "\ r \ n"; $ ("# Operation_content "). Val (content);},eval (Operation.endtime-operation.starttime));}
Pass the argument as far as the string!
This article is from the "Oriental Pavilion" blog, please be sure to keep this source http://lailai.blog.51cto.com/3362373/1692810
Function band Parameters of settimeout