Use jquery.noconflict () at the end of a version of jquery source code to release control of the “” identifier; Then put another version of jQuery’s “” identifier under control; Then put another version of jQuery’s “” identifier under control; Then put the “” and jQuery of another version into the temporary variable space, so that the” $” of the two versions of jQuery do not conflict. If you have used jQuery before, you know that different versions of jQuery can cause conflicts. The following article gives you an introduction.
Case: resolve a conflict between jQuery1.3.2 and 1.4.2. (This example passed the test!)
Step 1: Add a sentence at the end of the 1.4.2 source code:
var $j4 = jQuery.noConflict(true);
The reason why it is added in the source code, rather than when it is needed as most articles do, is because many plugins based on 1.4.2 need to be added here, so that too many plugins add this line of code to avoid duplication. JQuery 1.4.2 and jQuery 1.4.2 Plugins based on 1.4.2 can no longer use jQuery and reference permissions are abandoned. Plugins based on 1.4.2 can no longer use jQuery and reference permissions are abandoned. JQuery and jQuery are no longer available for plugins based on 1.4.2. Also give a new namespace for $j4, which is an attribute of window. If you look at the 1.4.2 source code, you can see that it actually does these two sentences:
window. $=_
window.jQuery=_jQuery;
Window. =temp=_temp=temp (return namespace);
Step 2: Add the following code to the header of all plug-ins based on the 1.4.2 framework:
var _temp
,_tempjQuery = window.jQuery;
Put $and jQuery from jQuery1.3.2 into a temporary variable space:
window.
j4;
This sentence and the following sentence are for the code in the middle to use jQuery properly. For the back. For the back. The following j4 is to give them the correct reference.
window.jQuery = $j4;
There are three reasons to put a temporary variable store first:
① We don’t want to change a lot of jQuery plug-in source code, it is best not to change, if at all, change as little as possible. It is also a good idea to add modified code to the end of the header, leaving the original code in the middle untouched.
(2). Because the had abandoned the jQuery 1.4.2 and control, but the existing plug-in code and use them for reference, because the plug-in could not predict conflict, even conflict with others to develop plug-ins must use control, but the existing plug-in code and use them for reference, because the plug-in could not predict conflict, The existing plugin code uses them as references even if there is a conflict, because plug-ins cannot predict the conflict, and even if there is a conflict, the plugin must be used or referenced by jQuery unless it is not a plugin under jQuery.
③ To prevent the plugin from using Windows directly. JQuery to window.jQuery, jQuery to window.jQuery, jQuery to window.jQuery, jQuery to window.jQuery It’s rare, but just in case.
The original code in the middle does not move, and the following code is added at the end:
window. =temp = _temp=temp; // return the reference permission to $to jQuery1.3.
window.jQuery = _tempjQuery; // Return the jQuery reference permission to jQuery1.3.
Step 3: $j4(element) is the only way to use jQuery1.4.2 based pickers.
Summary: Possible solution so far: jQuery1.4.2 completely drop and jQuery control permissions. 1.3.2 Relinquishing the control permission of jQuery. 1.3.2 Relinquishing the control permission of jQuery. JQuery can also be relinquished, but give the individual name j3. Prototype is best placed after jQuery1.3.2, which gets j3. Prototype is best placed after jQuery1.3.2, which gets j3. Prototype is best placed after jQuery1.3.2, the control permissions it gets. However, in order to use jQuery1.4.2, you will have to use $j4 to reference it. However, no matter how many jQuery framework version conflicts there are, they are all solved. If jQuery 1.2 is available, follow the steps in (2) and change the first step to:
var $j2 = jQuery.noConflict(true);
The third step is $j2(Element). It’s all the same.