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

How to solve jQuery conflict problem

藏色散人
藏色散人 Original
2021-01-18 10:33:04 2679browse

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") });

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 自定义访问符号") });

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!

Statement:
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