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

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

    You can try default functionality of 'apply()' something like this, you can pass more number of arguments as your requirement in the array

    function postinsql(topicId)
    {
      //alert(topicId);
    }
    setTimeout(
           postinsql.apply(window,["mytopic"])
    ,500);
    

提交回复
热议问题