我无法从JSF框架中删除原型(RichFaces 3.3.3)。如果我尝试noConflict并尝试接管$它会破坏我的应用程序框架,因为它与原型紧密结合。
有没有办法可以做到这一点:
jQuery(function() {
/*
some code that within this domready function
allows me to use $() within this function
and not interfere with $ being used for prototype
outside?
*/
});
答案 0 :(得分:7)
是的,它已经作为ready
处理程序的第一个参数传入,只需使用:
jQuery(function($) {
$("selector").doSomething();
});
//$ is still prototype here
答案 1 :(得分:1)
通常,您可以编写var $ = jQuery;
来替换单个函数中的$
符号。
在您的特定情况下,您还可以使用回调的第一个参数。
答案 2 :(得分:0)
将此link作为参考,您可以执行以下操作:
jQuery(function($) { // like Nick Craver
});
并调用jQuery所需的函数:
var yourFunction = function(){
var $ = this;
};
yourFunction.call(jQuery);
...
var yourFunction = (function($){
return function() {
// $ -> jQuery
};
})(jQuery);
...
var yourFunction = (function(){
var $ = this;
return function() {
// $ -> jQuery
};
}).call(jQuery);
答案 3 :(得分:0)
我工作组的标准:
jQuery.noConflict();
(function ($) {
//Do jQuery stuff using $ here.
})(jQuery);
//Do prototype stuff using $ here