我已将这些文件添加到 jsfiddle,您确定甚至需要 Prototype 吗?我已将其注释掉并替换为 jQuery(因为注释文件似乎需要它,组合的 [main] 文件也需要它)。
这样做后,我在页面加载时没有错误。
<!-- prototype -->
<!--script src="http://pastebin.com/raw.php?i=Cibn1NA2"></script-->
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<!--script>jQuery.noConflict();</script-->
<!-- comments -->
<script src="http://pastebin.com/raw.php?i=YisnTuBM"></script>
<!-- main = Modernizr + extras -->
<script src="http://pastebin.com/raw.php?i=n5dnr6i7"></script>
编辑评论: 第二小提琴展示 jQuery 的使用noConflict()
:
设置 - 要么不注释两个脚本标签,要么尝试注释一个或另一个,看看你得到了哪些错误。
测试使用addClass
jQuery 的addClassName
函数和 Prototype 的函数来查看哪个版本$
处于活动状态。一种或其他方法将失败,具体取决于当时哪种$
方法处于活动状态。
<!-- Comment one of these script tags, or leave both uncommented for noConflict mode -->
<!-- jQuery must come second in order to properly use noConflict -->
<script src="https://ajax.googleapis.com/ajax/libs/prototype/1.7.1.0/prototype.js"></script>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
测试:
// local var for jQuery - this might be undefined if jQuery not imported
var jQuery = window["jQuery"];
// if jQuery exists, put into noConflict mode - i.e. return jQuery $ to Prototype $
if (jQuery) jQuery.noConflict();
try {
// addClassName is prototype only, not jquery
$("output").addClassName("prototype");
setOutput("$.addClassName ok");
} catch (e) {
setOutput("Prototype > $.addClassName error: " + e);
}
try {
// addClass is jquery only, not prototype
$("output").addClass("jquery");
setOutput("$.addClass ok");
} catch (e) {
setOutput("jQuery > $.addClass error: " + e);
}
try {
// try using jQuery with the 'full' jQuery name
jQuery("output").addClass("jquery");
setOutput("jQuery.addClass ok");
} catch (e) {
setOutput("jQuery > jQuery.addClass error: " + e);
}
// wrap the code that needs $ to be jQuery $ in a function.
// and pass in jQuery to be aliased as $ within the function.
(function($) {
try {
$("output").addClass("jquery");
setOutput("$.addClass ok when wrapped");
} catch (e) {
setOutput("jQuery > wrapped $.addClass error: " + e);
}
}(jQuery));
包含 Prototype 和 jQuery 时的示例输出:
$.addClassName ok
jQuery > $.addClass error: TypeError: $(...).addClass is not a function
jQuery.addClass ok
$.addClass ok when wrapped