what exactly document-ready means in jquery

前端 未结 3 1775
天命终不由人
天命终不由人 2020-12-18 10:46

Let us say I have a HTML page that contains a javascript file:

The base.js is like this:

$(document).ready(function () {
   obj.init();
}

// .....         


        
3条回答
  •  臣服心动
    2020-12-18 11:41

    The ready event happens when the document is loaded and parsed.

    This includes all Javascript files, but not images.

    The ready event happens after the document is parsed. Some browsers have a specific event for this, in other browsers jQuery uses a timer that polls the status of the document. This means that the event happens either as soon as the entire document is parsed, or slightly later, depending on the browser. This is normally not a problem, as it doesn't happen before anything of the document is parsed.

    If you need all images to be loaded before you do something, you should use the load event instead.

提交回复
热议问题