Home > Web Front-end > JS Tutorial > How to solve jQuery conflict problem

How to solve jQuery conflict problem

藏色散人
Release: 2022-12-30 11:11:59
Original
2760 people have browsed it

Solution to the jQuery conflict problem: 1. Release the use rights of the $ symbol in the jQuery framework; 2. Customize an nj to replace the function of $, with statements such as "var nj=jQuery.noConflict(); nj(function(){}”

How to solve jQuery conflict problem

The demonstration environment of this tutorial: windows7 system, jquery1.2.6 version, Dell G3 computer.

Recommended : jQuery video tutorial

Solution to conflict problem 1:

Take a step back and release the use rights of the $ symbol in the jQuery framework.

In fact, $ is just an alias for jquery. If we need to use another js library other than jquery, we can return control to the library by calling $.noConflict().

Note Point: The release operation must be written before writing other jQuery code

You cannot use $ after releasing, use jQuery instead

jQuery.noConflict();
jQuery(function () {
      alert("hellow")
 });
Copy after login

Solution to the conflict problem 2:

Customized access symbols

Customize a nj to replace the function of $

var nj =jQuery.noConflict();
nj(function(){
    alert("hello inj 自定义访问符号")
});
Copy after login

The above is the detailed content of How to solve jQuery conflict problem. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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