Home > Web Front-end > JS Tutorial > A brief discussion on several solutions to jQuery multi-library conflict problems

A brief discussion on several solutions to jQuery multi-library conflict problems

青灯夜游
Release: 2020-11-17 18:08:22
forward
1959 people have browsed it

A brief discussion on several solutions to jQuery multi-library conflict problems

Related recommendations: "jQuery Video Tutorial"

Method 1: Use noConflict(): discard $, replace $ with jQuery

jQuery.noConflict();
Copy after login

Method 2: Custom variables: discard $ and define a new $y variable to replace $

var $y = jQuery.noConflict();
Copy after login

Method 3: Use statement block ①: Use $

jQuery.noConflict();
jQuery(document).ready(function ($){
    //此时整个ready事件中使用的$为jQuery,js中定义的$;
});
Copy after login

inside the local area. Method 4: Use statement block ②: Call the function directly, use $ instead of jQuery, jQuery is written in Later, common methods

jQuery.noConflict();
(function($){
    //此时在这个语句块中使用的$为jQuery,js中定义的$;
})(jQuery)
Copy after login

For more programming-related knowledge, please visit: Programming Video Course! !

The above is the detailed content of A brief discussion on several solutions to jQuery multi-library conflict problems. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:cnblogs.com
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