Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 一段时间后删除Ajax加载程序映像_Javascript_Jquery_Ajax - Fatal编程技术网

Javascript 一段时间后删除Ajax加载程序映像

Javascript 一段时间后删除Ajax加载程序映像,javascript,jquery,ajax,Javascript,Jquery,Ajax,我有一个ajax加载程序,它在单击按钮后显示,代码如下: jQuery(document).ready(function($){ { $.getElementById('form').onsubmit = function () { $.getElementById('submit').style.display = 'block'; $.getElementById('loading2').style.display = 'block';

我有一个ajax加载程序,它在单击按钮后显示,代码如下:

jQuery(document).ready(function($){
{
        $.getElementById('form').onsubmit = function () {
        $.getElementById('submit').style.display = 'block';
        $.getElementById('loading2').style.display = 'block';
        };
    }(document));
});
HTML:

'
我希望ajax加载程序在大约10秒后消失


请让我知道

您可以在10秒后使用此选项隐藏加载程序

setTimeout(function() {
    $('#loading').hide(); // I wasnt sure which one you wanted to hide
    $('#loading2').hide();
}, 10000);
同时看看你的代码,我不确定这是否会奏效。另外,如果您使用的是jQuery,那么您实际上不需要使用普通Javascript,这样您的代码就可以更改为这样

jQuery(document).ready(function($){
    $('#form').submit(function () {
        $('#submit').css('display', 'block');
        $('#loading2').css('display', 'block');
    });
});
注意:为了让jQuery函数在setTimeout中工作,应该将其包装在setTimeout中

function() { ... }

您可以使用javascript setTimeout
$(function() {
// setTimeout() function will be fired after page is loaded
// it will wait for 10 sec. and then will fire
// $("#successMessage").hide() function

setTimeout(function() {
$("#loading").hide('blind', {}, 500)
}, 10000);
});
function() { ... }