In some cases, we might use multiple JavaScript libraries in one page, because the $ identifier is used in multiple libraries, so we need a way to resolve the naming conflict, and the jquery Noconflict () method solves the problem well. jquery calls this method to pass the control permission on the $ identifier to other libraries for use.
The reference examples are as follows:
< Script src="Prototype.js"></script><!-- Referenced library 1 -- < Script src="Jquery.js"></script> <!-- referenced library 2 -- < Script > Jquery.noconflict (); / * JQuery Release the $ the right to control */ </ Script > < Script src="Myscript.js"></script> <!-- wrote it yourself. JS code, at which time the $ identifier is referenced in the library prototype.js- - |
As the code in the table shows, we first referenced the Prototype.js library and then referenced the Jquery.js library, at which time the jquery library had control over the $ identifier. Call the Noconflict () method, at which time jquery releases control over the $ identifier and transfers it to prototype.js.
jquery frees the use of the $ identifier, so all subsequent jquery uses jquery instead, such as $ (document). Ready (function () {}), which needs to be written in jquery (document). Ready (function () {}). Of course, love. Inside the ready function, we also have a way to re-enable jquery to use the $ identifier-using a callback function, but only within the ready function. Method: JQuery (document). Ready (function ($) {///where the identifier} can be used normally ).
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
jquery solves the problem of naming conflicts that are caused by referencing multiple JavaScript libraries