1

我需要延迟页面的重新加载。现在,我有这个:

$('div.navigation_sorter ul li a.delete').click(function(event){
                event.preventDefault();
                var li = $(this).closest('li');
                $.post('<?php echo site_url('admin/navigation/delete_link');?>', { link: li.attr('id')}, function(data){
                    $('<div class="feedback info"><p>'+ data +' has been deleted</p></div>').insertAfter('.navigation_sorter').delay(800);
                    window.location = '<?php echo current_url();?>';
                });
            });

这显然是行不通的。有人知道如何将重新加载延迟至少 3 秒左右吗?

4

4 回答 4

15

使用setTimeout在一定时间后执行一个函数:

$('div.navigation_sorter ul li a.delete').click(function(event){
                event.preventDefault();
                var li = $(this).closest('li');
                $.post('<?php echo site_url('admin/navigation/delete_link');?>', { link: li.attr('id')}, function(data){
                    $('<div class="feedback info"><p>'+ data +' has been deleted</p></div>').insertAfter('.navigation_sorter')
                    setTimeout(function(){
                         window.location = '<?php echo current_url();?>';
                    }, 3000);               
                });
            });
于 2010-02-18T10:17:18.793 回答
3

jQuery .delay 方法仅用于延迟函数链,您想使用 SetTimeout():

$('div.navigation_sorter ul li a.delete').click(function(event){
                event.preventDefault();
                var li = $(this).closest('li');
                $.post('<?php echo site_url('admin/navigation/delete_link');?>', { link: li.attr('id')}, function(data){
                    $('<div class="feedback info"><p>'+ data +' has been deleted</p></div>').insertAfter('.navigation_sorter');
                    setTimeout('reload()', 800);
                });
            });

function reload() { window.location = '<?php echo current_url();?>'; }

于 2010-02-18T10:17:12.570 回答
1

setTimeout应该做的工作,

   $('div.navigation_sorter ul li a.delete').click(function(event)
    {
        event.preventDefault();
        var li = $(this).closest('li');
        $.post('<?php echo site_url('admin/navigation/delete_link');?>', 
                { 
                  link: li.attr('id')
                }, function(data)
                 {
                    $('<div class="feedback info"><p>'+ data +' has been deleted</p>' +
                      '</div>').insertAfter('.navigation_sorter').delay(800);

                        setTimeout( function() 
                        {
                          window.location = '<?php echo current_url();?>';
                        }, 3000);
                    });
                });
于 2010-02-18T10:17:04.097 回答
0

试试这个,节省混合 php 和 jQuery,"."重新加载当前页面。

setTimeout(window.location = ".", 600);
于 2015-09-07T00:45:52.307 回答