Example of jQuery.holdReady of method usage

  • 2020-05-09 18:12:23
  • OfStack

This article illustrates the use of the jQuery.holdReady () method as an example. Share with you for your reference. The specific analysis is as follows:

This method suspends or restores the jQuery.ready () event.
Calling this method delays jQuery's ready event, which means that the ready event handling method is not executed even though the document has been loaded.
The jQuery.holdReady () method can be called multiple times to delay the ready event of jQuery, and when the 1 definite condition is met, the delay can be lifted by setting the parameter of this method to false, 11. Method 1 is generally used for dynamic script loading, until the script is loaded, and then unlocks the delay for the jQuery.ready () event by setting the parameter of this method to false.

Grammatical structure:

jQuery.holdReady(hold)

Parameter list:

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

If the value is false, the delay for the jQuery.ready () event is lifted.

Example code:

Example 1:


<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="//www.ofstack.com/" />
<title> The home of the script </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(" I don't get popped up ");
})
</script>
</head>
<body>
  
</body>
</html>

In the code above, jQuery.holdReady (true) is added, so the functions in ready() are not executed even though the document is loaded.
Example 2:


<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="//www.ofstack.com/" />
<title> The home of the script </title>
<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>
</head>
<body>
<button id="first"> Click test to pop up </button>
<button id="second"> Lift the delay </button>
<script type="text/javascript">
jQuery.holdReady(true) 
$(document).ready(function(){
  $("#first").click(function(){
    alert(" I don't get popped up ");
  })
})
$("#second").click(function(){
  jQuery.holdReady(false);
})
</script>
</body>
</html>

When the delay is removed, it will pop up.

I hope this article is helpful for you to design jQuery program.


Related articles: