对此有读:http://docs.jquery.com/Using_jQuery_with_Other_Libraries
显示很好的例子:)
重写$ -FUNCtion
但是,您可以通过在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>
你已经解决了这个问题?您需要进一步的帮助吗?或者您可以将问题标记为已回答? – 2009-06-23 10:44:36