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

前端 未结 28 1894
既然无缘
既然无缘 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:07

    You can pass the parameter to the setTimeout callback function as:

    setTimeout(function, milliseconds, param1, param2, ...)

    eg.

    function myFunction() {
      setTimeout(alertMsg, 3000, "Hello");
    }
    
    function alertMsg(message) {
        alert(message)
    }
    

提交回复
热议问题