jQuery API jQuery API 中英文对照版 - jQuery在线查询手册
$.noConflict()
$.noConflict()

运行这个函数将变量$的控制权让渡给第一个实现它的那个库。这样可以确保jQuery不会与其他库的$对象发生冲突。

在运行这个函数后,就只能使用iQuery变量访问iQuery对象。例如,在要用到$("div p")的地方,就必须换成iQuery("div p")。

返回值:undefined

 

示例 :

将$引用的对象映射回原始的对象,让渡变量$

jQuery 代码:

jQuery.noConflict(); 
// 开始使用jQuery
jQuery("div   p").hide();
// 使用其他库的 $() 
$("content").style.display = 'none'; 
示例:

恢复使用别名$,然后创建并执行一个函数,在这个函数的作用域中仍然将$作为jQuery的别名来使用。在这个函数中,原来的$对象是无效的。这个函数对于大多数不依赖于其他库的插件都十分有效。

jQuery 代码:

jQuery.noConflict();
(function($) {
  $(function() {
    //   使用 $ 作为 jQuery 别名的代码
 }); 
})(jQuery);
// 使用 $ 作为别名的其他库的代码
 
$.noConflict()

Run this function to give control of the $ variable back to whichever library first implemented it. This helps to make sure that jQuery doesn't conflict with the $ object of other libraries.

By using this function, you will only be able to access jQuery using the 'jQuery' variable. For example, where you used to do $("div p"), you now must do jQuery("div p").

Return value: undefined

 

Example:

Maps the original object that was referenced by $ back to $

jQuery.noConflict(); 
// Do something with jQuery   
jQuery("div p").hide();   
// Do something with another library's $()   
$("content").style.display = 'none';  

Example:

Reverts the $ alias and then creates and executes a function to provide the $ as a jQuery alias inside the functions scope. Inside the function the original $ object is not available. This works well for most plugins that don't rely on any other library.

 jQuery.noConflict(); 
  (function($) {
      $(function() {
       // more code using $ as alias to jQuery 
    });
   })(jQuery);
   // other code using $ as an alias to the other library