zoukankan      html  css  js  c++  java
  • jQuery $(document).ready()

    Table of Contents

    Whenever you use jQuery to manipulate your web page, you wait until the document ready event has fired. The document ready event signals that the DOM of the page is now ready, so you can manipulate it without worrying that parts of the DOM has not yet been created. The document ready event fires before all images etc. are loaded, but after the whole DOM itself is ready.

    jQuery Document Ready Example

    Here is a jQuery document ready listener example:

    $(document).ready(function() {
    
        //DOM manipulation code
    
    });
    

    You call jQuery's $ function, passing to it the document object. The $ function returns an enhanced version of thedocument object. This enhanced object has a ready() function you can call, to which you pass a JavaScript function. Once the DOM is ready, the JavaScript function is executed.

    Inside the function passed to the ready() method, you can execute all the jQuery and JavaScript code you need, in order to initialize / enhance the HTML elements in your page. You will see many examples of this, in the following pages.

    Multiple Document Ready Listeners

    jQuery allows you to register multiple document ready listeners. Just call $(document).ready() multiple times. Here is a multiple document ready listener example:

    $(document).ready(function() {
    
        //DOM manipulation code
    
    });
    
    
    $(document).ready(function() {
    
        //DOM manipulation code
    
    });
    

    The two listener functions registered in this example will both get called when the DOM is ready. They will get called in the order they were registered.

    Registering multiple document ready event listeners can be really useful if you include HTML pages inside other HTML pages (e.g. using server side include features of your backend / web server). You may need some page initialization to occur both in the outer and inner page. Thus both the outer and inner page can register a document ready listener, and perform the page initialization they both need.

  • 相关阅读:
    (zt)在PHP中使用全局变量
    (zt)Flash与C++交互
    (zt)关于Flash Socket通信的安全策略问题的一点心得
    (zt)svn 随服务器启动
    使用InstallShield安装和卸载SQL Server数据库(利用sql脚本)
    异常查看部分代码
    VC为控件添加背景
    深入分析MFC文档视图结构
    VC数据库编程概述
    (转)WEB程序打包详解:(连接SQL2005数据库,修改配置文件,建立虚拟目录)
  • 原文地址:https://www.cnblogs.com/hephec/p/4571017.html
Copyright © 2011-2022 走看看