我如何让我的 javascript 超时只有 3 秒?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13394182/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 18:37:45  来源:igfitidea点击:

How would I make my javascript timeout for only 3 seconds?

javascriptfunctiontimeoutseconds

提问by user1824806

If 4e3 is equal to 4 seconds. What would I use for 3 Secs? or 2 Secs?

如果 4e3 等于 4 秒。我会用什么 3 秒?还是2秒?

<SCRIPT LANGUAGE="javascript">
$( function() {
 setTimeout(function() {
        $('#loadingque').trigger('click');
    }, 4e3);
});
</script>

回答by elclanrs

If you understandwhy 4e3is 4000 then you can figure out what 3000 looks like. eNmeans 10 to the power N, so 3 times 10 to the power 3 is 3000, or 3e3.

如果您了解为什么4e3是 4000,那么您就可以弄清楚 3000 的样子。eN意味着10 to the power N,所以 3 次 10 的 3 次方是 3000,或者3e3

回答by Pravin Kumar

setTimeout(function() {
      // Do something after 5 seconds
}, 5000);

jQuery(document).ready(function () {`enter code here`
    //hide a div after 3 seconds
    setTimeout( "jQuery('#div').hide();",3000 );
});

Hope these will help u..

希望这些会帮助你..

回答by Akhil Sekharan

It takes milliseconds

需要几毫秒

setTimeout(function() {
    document.write(new Date());
}, 3000);

回答by ddarellis

var runCount = 0;
var maxCount = 1000000;

function timerMethod()
{
    runCount++;
    if(runCount >= maxCount)
    {
        clearInterval(timerId);
    }
    $('#loadingque').trigger('click');
    console.log(runCount + "of" + maxCount);
}

var timerId = setInterval(timerMethod, 3000);

this is running every 3000ms for maxCount times

这是每 3000 毫秒运行一次 maxCount 次