Delaying click event

后端 未结 4 1132
滥情空心
滥情空心 2021-02-20 11:54

I\'m wondering whether there\'s a simple way to delay the click event from being processed for a specified period of time. For example we could have

$(\'#someEle         


        
4条回答
  •  借酒劲吻你
    2021-02-20 12:44

    jQuery's ajax functionality provides exactly what you are looking for. You can define a callback function to run after your ajax request.

    Something like this:

    $('#someElement').click(function(event){
        event.preventDefault();
        var loc = $(this).attr('href');
        $.ajax({
            url: "test.html",
            complete: function(){
                // Handle the complete event
                loc = $(this).attr('href');
                window.location.href = loc;
            }
        });
    });
    

    You may want to use ajaxStop instead of complete, it seems like your motivation for delaying navigation is because you have a bunch of asynchronous stuff going on and you want to make sure all your ajax stuff is complete before you navigate to that page.

    Regardless I would recommend looking at http://api.jquery.com/Ajax_Events/ (a very useful page of documentation).

提交回复
热议问题