Home > Web Front-end > JS Tutorial > body text

Learn how to use noConflict() in jQuery

青灯夜游
Release: 2018-10-08 16:58:06
forward
1787 people have browsed it

In this article, we have compiled relevant knowledge points about learning the usage of noConflict() in jQuery. Friends who need it can learn it.

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 purpose, jQuery provides the noConflict() method

Release the identifier

will release control of the $identifier

In this way, other scripts can use

$.noConflict();
Copy after login

full name instead of

Use jQuery full name instead of abbreviation $

jQuery(document).ready(function(){
 jQuery("button").click(function(){
  jQuery("p").text("jQuery 仍然在工作!");
 });
});
Copy after login

Create abbreviations

You can create your own abbreviations

noConflict() can return a reference to jQuery

Save it into a variable, and then, Use this variable instead of $

var jq = $.noConflict();
jq(document).ready(function(){
 jq("button").click(function(){
  jq("p").text("jQuery 仍然在工作!");
 });
});
Copy after login

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 仍然在工作!");
 });
});
Copy after login
outside the function.

The above is the detailed content of Learn how to use noConflict() in jQuery. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:jb51.net
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!