jQuery.holdReady()方法用法執行個體_jquery

來源:互聯網
上載者:User

本文執行個體講述了jQuery.holdReady()方法用法。分享給大家供大家參考。具體分析如下:

此方法可以暫停或者恢複jQuery.ready()事件。
調用此方法可以延遲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>

當點擊解除延遲之後,就可以彈出了。

希望本文所述對大家的jQuery程式設計有所協助。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.