How can I pass a parameter to a setTimeout() callback?

前端 未结 28 1907
既然无缘
既然无缘 2020-11-21 07:31

I have some JavaScript code that looks like:

function statechangedPostQuestion()
{
  //alert("statechangedPostQuestion");
  if (xmlhttp.readyState==         


        
28条回答
  •  礼貌的吻别
    2020-11-21 08:18

    In modern browsers, the "setTimeout" receives a third parameter that is sent as parameter to the internal function at the end of the timer.

    Example:

    var hello = "Hello World";
    setTimeout(alert, 1000, hello);

    More details:

    • https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers.setTimeout
    • http://arguments.callee.info/2008/11/10/passing-arguments-to-settimeout-and-setinterval/

提交回复
热议问题