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

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

    if you want to pass variable as param lets try this

    if requirement is function and var as parmas then try this

    setTimeout((param1,param2) => { 
         alert(param1 + param2);
         postinsql(topicId);
    },2000,'msg1', 'msg2')
    

    if requirement is only variables as a params then try this

    setTimeout((param1,param2) => { alert(param1 + param2) },2000,'msg1', 'msg2')

    You can try this with ES5 and ES6

提交回复
热议问题