How to call a jquery function onload with some delay?

前端 未结 5 788
闹比i
闹比i 2021-01-23 21:53

How to call a jquery function onload with some delay?

I want to call a function like this on load with some delay

$(\".sample\").live(\'click\',function(         


        
相关标签:
5条回答
  • 2021-01-23 22:01

    you could use setTimeout function you must refactor your code as something like this

        //2 seconds wait before calling doJob
        $(".sample").live('click',function(){ setTimeout(doJob, 2000);});
    
        function doJob(){
            var id=$(this).attr("id");
            //other statements ...
        }
    
    0 讨论(0)
  • 2021-01-23 22:07

    This will wait 1 second and then assign the event handler...

    function assignSampleClick() {
        $(".sample").live('click',function(){
            var id=$(this).attr("id");
        });
    }
    
    // document ready
    $(function() {
        setTimeout(assignSampleClick, 1000);
    });
    
    0 讨论(0)
  • 2021-01-23 22:12

    Try it like this..

    $(document).ready(function () {
    setTimeout(function () {
    $(".sample").live('click',function(){
    var id=$(this).attr("id");
       }, 3000);
    }, 3000);
    

    This will fire on page load after 3 seconds delay.

    0 讨论(0)
  • 2021-01-23 22:16

    Try to use Timer Plugin

    $(this).oneTime(1000, function() {
         // some action here
    });
    
    0 讨论(0)
  • 2021-01-23 22:20

    try this

       var demora = window.setInterval(lerolero, 3000);
    function lerolero() {
         $("#ovo").css("display", "block");
    	}

    0 讨论(0)
提交回复
热议问题