zoukankan      html  css  js  c++  java
  • jQuery.holdReady()方法用法实例

    调用此方法可以延迟jQuery的ready事件,也就是说尽管文档已经加载完成,也不会执行ready事件处理方法。
    可以多次调用jQuery.holdReady()方法,以延迟jQuery的ready事件,当满足一定条件时,再通过将此方法的参数设置为false,一一解除延迟。方法一般用于动态脚本加载,知道脚本加载完成然后再通过将此方法的参数设置为false,解除对jQuery.ready()事件延迟。

    语法结构:

    jQuery.holdReady(hold)

    参数列表:

    参数

    描述

    hold

    如果值为true,则会延迟jQuery.ready()事件。
    如果值为false,则会解除对jQuery.ready()事件延迟。

    如果值为false,则会解除对jQuery.ready()事件延迟。

    实例代码:

    实例一:

     

    <!DOCTYPE html>

    <html>

    <head>

    <meta charset=" utf-8">

    <meta name="author" content="http://www.jb51.net/" />

    <title>脚本之家</title>

    <script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>

    <script type="text/javascript">

    jQuery.holdReady(true);

    $(document).ready(function(){

      alert("我不会被弹出");

    })

    </script>

    </head>

    <body>

      

    </body>

    </html>

    在以上代码中,由于添加了 jQuery.holdReady(true),所以尽管文档加载完成,也不会执行ready()中的函数。

    实例二:

    <!DOCTYPE html>

    <html>

    <head>

    <meta charset=" utf-8">

    <meta name="author" content="http://www.jb51.net/" />

    <title>脚本之家</title>

    <script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>

    </head>

    <body>

    <button id="first">点击测试弹出</button>

    <button id="second">解除延迟</button>

    <script type="text/javascript">

    jQuery.holdReady(true) 

    $(document).ready(function(){

      $("#first").click(function(){

        alert("我不会被弹出");

      })

    })

    $("#second").click(function(){

      jQuery.holdReady(false);

    })

    </script>

    </body>

    </html>

    当点击解除延迟之后,就可以弹出了。

  • 相关阅读:
    第三题 bfw在睡觉
    第二题 bfw和zhk的故事
    第一题 奶牛散步
    AC加油站7月比赛总结
    暑期机房联赛
    题解 P5663 【加工零件【民间数据】】
    题解 P1052 【过河】
    并发编程之进程
    网络编程socketserver
    网络编程之黏包
  • 原文地址:https://www.cnblogs.com/lgx5/p/5676529.html
Copyright © 2011-2022 走看看