events load and ready not firing

前端 未结 1 363
一个人的身影
一个人的身影 2021-01-27 05:35

This is my code:

$(document).on(\'ready load click\',function(){
    console.log(\'hiihuhu\')
})

I included the jquery script above. The proble

相关标签:
1条回答
  • 2021-01-27 06:04

    Which Version of jQuery are you using

    According to jQuery docs

    $(document).on( "ready", handler ), deprecated as of jQuery 1.8 and removed in jQuery 3.0. Note that if the DOM becomes ready before this event is attached, the handler will not be executed.

    $( window ).load(function() {
     alert("hello");
    });
    
    $(document).ready(function(){
       $(document).on('click',function(){
         alert("in click event");
         });
    });
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <div>hello</div>

    1. Window onload: :Is fired when all the content including images has been loaded

    2. document.ready : Is fired after html document is loaded

    So i guess you cannot combine all three events ready,load and click the way you have tried

    Hope it helps

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