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

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

    The easiest cross browser solution for supporting parameters in setTimeout:

    setTimeout(function() {
        postinsql(topicId);
    }, 4000)
    

    If you don't mind not supporting IE 9 and lower:

    setTimeout(postinsql, 4000, topicId);
    

    setTimeout desktop browser compatibility

    setTimeout mobile browser compatibility

    https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers/setTimeout

提交回复
热议问题