The following code:
Copy codeThe Code is as follows:
JQuery. noConflict ();
JQuery (document). ready (function (){
// Your Code ....
});
JQuery. noConflict () Details:
Overview
Run this function to assign control of variable $ to the first database that implements it. This helps ensure that jQuery does not conflict with the $ object of other libraries. After running this function, only jQuery variables can be used to access jQuery objects. For example, to use $ ("div p"), you must replace it with jQuery ("div p ").
Note: This function must be used after you import the jQuery file and before importing another library that causes the conflict. Of course, it should also be before other conflicting libraries are used, unless jQuery is the last imported.
Description:
Maps $ referenced objects back to the original objects.
JQuery code:
Copy codeThe Code is as follows:
JQuery. noConflict ();
// Use jQuery
JQuery ("div p"). hide ();
// Use $ () for other libraries ()
$ ("Content"). style. display = 'none ';
Description:
Resume the use of Alias $, and then create and execute a function. In the scope of this function, $ is still used as the alias of jQuery. In this function, the original $ object is invalid. This function is very effective for most plug-ins that do not depend on other libraries.
JQuery code:
Copy codeThe Code is as follows:
JQuery. noConflict ();
(Function ($ ){
$ (Function (){
// Use $ as the jQuery alias code
});
}) (JQuery );
// Other code of the database that uses $ as the alias
Description:
Create a new alias to use the jQuery object in the following library.
JQuery code:
Copy codeThe Code is as follows:
Var j = jQuery. noConflict ();
// JQuery-based code
J ("div p"). hide ();
// $ () Code based on other libraries
$ ("Content"). style. display = 'none ';