Home > Web Front-end > JS Tutorial > Two solutions to conflicts between jquery and js functions_jquery

Two solutions to conflicts between jquery and js functions_jquery

WBOY
Release: 2016-05-16 17:22:59
Original
1229 people have browsed it

If you have other requirements and want to continue using the original $() without conflicting with other class libraries, there are two solutions
one:

Copy code The code is as follows:

jQuery.noConflict();
jQuery(function($)
{
$("p").click(function() //You can use the $() method of the jquery class library to continue within the function
{
alert($(this).text());
})
})

var JsCOM_cr = $("cr"); // Outside the function, you can still use the $() method of JsCOM.js

Second:
Copy code The code is as follows:

jQuery.noConflict(); //Will The control rights of the variable $ are transferred to other class libraries. When using the $ symbol of the jquery class library, please use jQuery("#id");
(function($) { //Define the anonymous function and set the formal parameters to $
$(function() { //The $ inside the anonymous function is jQuery
$("div").click(function() {//Continue to use the $() method
alert($ (this).text());
})
})
})
(jQuery); //Use anonymous function and pass actual parameters jQUery
alert($("cr ")); //Using the $() function in the jsCOM.js class library
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