How to call a jquery function onload with some delay?

前端 未结 5 790
闹比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 ...
        }
    

提交回复
热议问题