jQuery.noConflict()
这有助于确保jQuery不会与其他库的$对象发生冲突。
在运行这个函数后,就只能使用jQuery变量访问jQuery对象。例如,在要用到$("div p")的地方,就必须换成jQuery("div p")。
注意: 这个函数必须在你导入jQuery文件之后,并且在导入另一个导致冲突的库之前 使用。当然也应当在其他冲突的库被使用之前,除非jQuery是最后一个导入的。
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").
NOTE: This function must be called after including the jQuery javascript file, but before including any other conflicting library, and also before actually that other conflicting library gets used, in case jQuery is included last.
返回值
jQuery
示例
将$引用的对象映射回原始的对象。
jQuery 代码:
恢复使用别名$,然后创建并执行一个函数,在这个函数的作用域中仍然将$作为jQuery的别名来使用。在这个函数中,原来的$对象是无效的。这个函数对于大多数不依赖于其他库的插件都十分有效。
jQuery 代码:
创建一个新的别名用以在接下来的库中使用jQuery对象。
jQuery 代码: