Detailed explanation of usage examples of jQuery.holdReady(hold)
Pause or resume the execution of the .ready() event.
The $.holdReady() method allows the caller to delay jQuery's ready event. This advanced functionality is typically done using a dynamic script loader, which loads JavaScript such as a jQuery plug-in, and allows additional ready events to occur even when the DOM may be ready. This method must be called early in the file, immediately after the
jQuery script like this. Calling this method after the ready event will have no effect even if it has been emitted.To delay the ready event, call $.holdReady(true) for the first time. When the ready event should be executed, $.holdReady(false) is called. Please note that multiple holds can be placed on the ready event, each calling $.holdReady(true) one by one. The ready event will not execute until all corresponding $.holdReady(false) has been posted and the normal file ready conditions are met.
jQuery.holdReady(hold) Return value type boolean
The jquery.holdReady() method allows jQuery's completion event to be locked by this function.
A typical application scenario for this advanced feature is dynamic loading of scripts, such as jQuery plug-ins, etc.
Before the attached script is loaded, the jQuery completion event will not be triggered even if the page is ready.
This function must be called in the front part of the page, such as in the tag, jQuery loads the next line.
Calling this function after the completion event is triggered has no effect.
Usage: First call .holdReady(true) [the completion event will be locked after the call]. When ready to fire the completion event, call .holdReady(false). It should be noted that
You can add multiple locks to the completion event, and each lock corresponds to a $.holdReady(false)[unlock] call.
jQuery's completion event will be triggered when all locks are released and the page is ready.
In fact, it is a security lock for some codes that need to rely on dynamic scripts.
The ready event will be executed after the required dynamic scripts are loaded, rather than after the DOM tree is successfully constructed.
Example code:
Example 1:
<!DOCTYPE html> <html> <head> <meta charset=" utf-8"> <meta name="author" content="" /> <title>php.cn</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>
In the above code, due to the addition of jQuery.holdReady(true), even though the document is loaded, it will not be executed. function in ready().
Example 2:
<!DOCTYPE html> <html> <head> <meta charset=" utf-8"> <meta name="author" content="" /> <title>php.cn</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>
When you click to release the delay, it will pop up.
Let’s look at a small example again
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <script type="text/javascript" src="../js/jquery-1.7.2.min.js"></script> <script type="text/javascript" src="index.js"></script> <title>Insert title here</title></head> <body> <input type="button" id="btn" value="呵呵"> </body> </html>
Then there are two js files
The first thing to load is index.js
$.holdReady(true);//将holdReady改为ture,点击按钮就没有任何效果,改为false就可以是用来里面的js事件$(function(){ $('#btn').click(function(){ alert(123); }); });
Write two js below The files index.js and hold.js
Only load index.js in jsp, decide whether to load hold.js in index.js
The code is as follows:
//hold.js$(function(){ alert('这是使用holdReady加载出来的'); }); //index.jsjQuery.holdReady(true) $.getScript("hold.js", function() { jQuery.holdReady(false); });
Load hold.js When calling a callback function, change true to false, so that the hold.js file can be loaded
The above is the detailed content of Detailed explanation of usage examples of jQuery.holdReady(hold). For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

The DirectX repair tool is a professional system tool. Its main function is to detect the DirectX status of the current system. If an abnormality is found, it can be repaired directly. There may be many users who don’t know how to use the DirectX repair tool. Let’s take a look at the detailed tutorial below. 1. Use repair tool software to perform repair detection. 2. If it prompts that there is an abnormal problem in the C++ component after the repair is completed, please click the Cancel button, and then click the Tools menu bar. 3. Click the Options button, select the extension, and click the Start Extension button. 4. After the expansion is completed, re-detect and repair it. 5. If the problem is still not solved after the repair tool operation is completed, you can try to uninstall and reinstall the program that reported the error.

Windows operating system is one of the most popular operating systems in the world, and its new version Win11 has attracted much attention. In the Win11 system, obtaining administrator rights is an important operation. Administrator rights allow users to perform more operations and settings on the system. This article will introduce in detail how to obtain administrator permissions in Win11 system and how to effectively manage permissions. In the Win11 system, administrator rights are divided into two types: local administrator and domain administrator. A local administrator has full administrative rights to the local computer

Detailed explanation of division operation in OracleSQL In OracleSQL, division operation is a common and important mathematical operation, used to calculate the result of dividing two numbers. Division is often used in database queries, so understanding the division operation and its usage in OracleSQL is one of the essential skills for database developers. This article will discuss the relevant knowledge of division operations in OracleSQL in detail and provide specific code examples for readers' reference. 1. Division operation in OracleSQL

Many friends still don’t know how to use Baidu Netdisk, so the editor will explain how to use Baidu Netdisk below. If you are in need, hurry up and take a look. I believe it will be helpful to everyone. Step 1: Log in directly after installing Baidu Netdisk (as shown in the picture); Step 2: Then select "My Sharing" and "Transfer List" according to the page prompts (as shown in the picture); Step 3: In "Friend Sharing", you can share pictures and files directly with friends (as shown in the picture); Step 4: Then select "Share" and then select computer files or network disk files (as shown in the picture); Fifth Step 1: Then you can find friends (as shown in the picture); Step 6: You can also find the functions you need in the "Function Treasure Box" (as shown in the picture). The above is the editor’s opinion

The KMS Activation Tool is a software tool used to activate Microsoft Windows and Office products. KMS is the abbreviation of KeyManagementService, which is key management service. The KMS activation tool simulates the functions of the KMS server so that the computer can connect to the virtual KMS server to activate Windows and Office products. The KMS activation tool is small in size and powerful in function. It can be permanently activated with one click. It can activate any version of the window system and any version of Office software without being connected to the Internet. It is currently the most successful and frequently updated Windows activation tool. Today I will introduce it Let me introduce to you the kms activation work

How to use the shortcut keys for merging cells In daily work, we often need to edit and format tables. Merging cells is a common operation that can merge multiple adjacent cells into one cell to improve the beauty of the table and the information display effect. In mainstream spreadsheet software such as Microsoft Excel and Google Sheets, the operation of merging cells is very simple and can be achieved through shortcut keys. The following will introduce the shortcut key usage for merging cells in these two software. exist

Potplayer is a very powerful media player, but many friends still don’t know how to use potplayer. Today I will introduce how to use potplayer in detail, hoping to help everyone. 1. PotPlayer shortcut keys. The default common shortcut keys for PotPlayer player are as follows: (1) Play/pause: space (2) Volume: mouse wheel, up and down arrow keys (3) forward/backward: left and right arrow keys (4) bookmark: P- Add bookmarks, H-view bookmarks (5) full screen/restore: Enter (6) multiple speeds: C-accelerate, 7) Previous/next frame: D/

I believe that many users are using the Xiaoma win7 activation tool, but do you know how to use the Xiaoma win7 activation tool? Then, the editor will bring you how to use the Xiaoma win7 activation tool. For those who are interested in this, please come to the following article Let's see. The first step is to go to "My Computer" after reinstalling the system, click "System Properties" in the upper menu, and check the Windows activation status. In the second step, click to download the win7 activation tool online and click to open it (there are many resources available everywhere). The third step is to open the Xiaoma activation tool and click "Activate Windows permanently". The fourth step is to wait for the activation process to complete activation. Step 5: Check the Windows activation status again and find that the system has been activated.
