jquery 手册
Ajax
属性(Attributes)
回调对象(Callbacks ..
核心(Core)
CSS
数据(Data)
延迟对象(Deferred o ..
尺寸(Dimensions)
效果(Effects)
事件(Events)
表单(Forms)
文档操作(Manipulati ..
杂项(Miscellaneou ..
位置(Offset)
插件编写(Plugin Aut ..
属性(Properties)
选择器(Selectors)
遍历(Traversing)
工具(Utilities)

Returns: ObjectObject jQuery.noConflict( Boolean removeAll )

Description: 放弃jQuery对$变量的控制.
  • version added: 1.0
  • jQuery.noConflict( Boolean removeAll )
  • removeAll 一个Boolean值,指明是否在全局范围移除所有的jQuery变量 (包含jQuery自己).

许多JavaScript库使用$作为一个函数或变量名,就像jQuery一样。 .如果我们需要使用另一个JavaScript库并同时使用jQuery,我们可以使用$.noConflict()返回其它库函数对$的控制:

<script type="text/javascript" src="other_lib.js"></script>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
  $.noConflict();
  // Code that uses other library's $ can follow here.
</script>
<script type="text/javascript" src="other_lib.js"></script>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
  $.noConflict();
  jQuery(document).ready(function($) {
    // Code that uses jQuery's $ can follow here.
  });
  // Code that uses other library's $ can follow here.
</script>

Examples:

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:

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

Example:

You can chain the jQuery.noConflict() with the shorthand ready for a compact code.
jQuery.noConflict()(function(){
    // code using jQuery
}); 
// other code using $ as an alias to the other library

Example:

创建一个不同的别号来替代jQuery,作用范围是在该行代码后面的脚本。
var j = jQuery.noConflict();
// Do something with jQuery
j("div p").hide();
// Do something with another library's $()
$("content").style.display = 'none';

例子:

完全将jQuery移入到一个一个其它对象的新的命名空间中.
var dom = {};
dom.query = jQuery.noConflict(true);