Home  >  Article  >  Web Front-end  >  jQuery.holdReady() usage method_jquery

jQuery.holdReady() usage method_jquery

WBOY
WBOYOriginal
2016-05-16 16:47:351366browse
Copy code The code is as follows:

holdReady: function( hold ) {
if ( hold ) {
jQuery.readyWait; // readyWait is a counter, indicating how many item ready events are left before execution

} else { jQuery.ready( true ); } }

Usage is as follows:

jQuery.holdReady( hold )

Function: Pause or resume the execution of the .ready() event

Parameter: hold is a boolean value, indicating whether Pause or resume the requested ready event

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. Even if the page is ready, jQuery's completion event will not be fired until the attached script has finished loading. This function must be called early in the page, such as in the tag, where jQuery loads the next line. Calling this function after the completion event has been fired 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 multiple locks can be added to the completion event, and each lock corresponds to a $.holdReady(false)[unlock] call. jQuery's completion event will be fired when all locks have been 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 is executed after the required dynamic scripts are loaded, rather than after the DOM tree is successfully built.
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn