文档说你可以像这样使用$ .noConflict():
jQuery.noConflict();
(function($) {
$(function() {
// more code using $ as alias to jQuery
});
})(jQuery);
// other code using $ as an alias to the other library
Run Code Online (Sandbox Code Playgroud)
它还声明调用它返回jQuery对象的实例,所以我可以这样做:
jQuery.noConflict()(function(){
// code using jQuery
});
// other code using $ as an alias to the other library
Run Code Online (Sandbox Code Playgroud)
但是,这种组合有效吗?
(function($) {
$(function() {
// more code using $ as alias to jQuery
});
})(jQuery.noConflict());
// other code using $ as an alias to the other library
Run Code Online (Sandbox Code Playgroud)
如果是这样,有没有理由不这样做?而且(如果它有效),为什么不总是使用这个方法来保证我们的闭包里面,$ == jQuery?
| 归档时间: |
|
| 查看次数: |
328 次 |
| 最近记录: |