This article introduces you to the noConflict() method in jQuery. Friends in need can refer to it. I hope it will be helpful to you. Likes and comments are also welcome.
noConflict()
jQuery uses the $ symbol as the abbreviation of jQuery
JavaScript frameworks include: MooTools, Backbone, Sammy, Cappuccino, Knockout, JavaScriptMVC, Google Web Toolkit, Google Closure, Ember, Batman and ExtJS, etc.
Some of these frameworks also use the $ symbol as abbreviation
If two different frameworks are used, use the same abbreviation symbol, May cause the script to stop running
For this reason, jQuery provides the noConflict() method
Release the identifier
will release control of the $identifier
In this way, other scripts can use
$.noConflict();
full name instead of
Use jQuery full name instead of abbreviation $
jQuery(document).ready(function(){ jQuery("button").click(function(){ jQuery("p").text("jQuery 仍然在工作!"); }); });
Create abbreviation
You can create your own abbreviation
noConflict() can return a reference to jQuery
Save it into a variable, then, Use this variable instead of $
var jq = $.noConflict(); jq(document).ready(function(){ jq("button").click(function(){ jq("p").text("jQuery 仍然在工作!"); }); });
Parameter passing
You can use the $ symbol as a variable and pass it to the ready method
In this way, you can pass it inside the function Use the $ symbol. You cannot use $
$.noConflict(); jQuery(document).ready(function($){ $("button").click(function(){ $("p").text("jQuery 仍然在工作!"); }); });
The above is the detailed content of In-depth understanding of the noConflict() method in jQuery. For more information, please follow other related articles on the PHP Chinese website!