How to call a jquery function onload with some delay?

前端 未结 5 837
闹比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: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);
    });
    

提交回复
热议问题