阅读以下内容: http: //docs.jquery.com/Using_jQuery_with_Other_Libraries
展示了很好的例子:)
重写 $-函数
但是,您可以在 jQuery 和其他库都加载后的任何时候调用 jQuery.noConflict() 来覆盖该默认值。例如:
<html>
<head>
<script src="prototype.js"></script>
<script src="jquery.js"></script>
<script>
jQuery.noConflict();
// Use jQuery via jQuery(...)
jQuery(document).ready(function(){
jQuery("div").hide();
});
// Use Prototype with $(...), etc.
$('someid').hide();
</script>
</head>
<body></body>
</html>
这会将 $ 恢复到其原始库。您仍然可以在应用程序的其余部分中使用“jQuery”。
此外,还有另一种选择。如果你想确保 jQuery 不会与另一个库冲突——但你想要一个短名称的好处,你可以这样做:
<html>
<head>
<script src="prototype.js"></script>
<script src="jquery.js"></script>
<script>
var $j = jQuery.noConflict();
// Use jQuery via $j(...)
$j(document).ready(function(){
$j("div").hide();
});
// Use Prototype with $(...), etc.
$('someid').hide();
</script>
</head>
<body></body>
</html>