The Window.settimeout method is used to delay the execution of a segment function (method). But it is in a certain defect when calling the specified method and passing the parameter. General direct reference, can only pass the parameters such as Word Fu, but for the object type can not be directly passed on, my method is to rewrite the Window.settimeout method, using the Apply back off,
| The code is as follows |
Copy Code |
| var _st = window.settimeout; Fref is the test function, Mdelay is the time Window.settimeout = function (Fref, mdelay) { if (typeof fref = = ' function ') { var Argu = Array.prototype.slice.call (arguments,2); var f = ( function () { Fref.apply (null, ARGU); }); Return _st (f, mdelay); } Return _st (Fref,mdelay); }
function test (x,y,z) { Alert (x+ "" +y+ "" +z); }
The first parameter is the function to execute, the second argument is the interval, and the subsequent argument is the value to pass in Window.settimeout (Test,1000,document.getelementbyid ("D"), ' abc ', ' 123 '); |