问题描述
我遇到与我的jQuery库冲突的motools库有问题:
I am having a problem with the motools library conflicting with my jQuery library:
这是代码:
<script language="Javascript" type="text/javascript" src="revamp/js/jquery-1.4.2.js"></script>
<script language="Javascript" type="text/javascript" src="revamp/js/jquery.blinds-0.9.js"></script>
<script type="text/javascript" src="js/mootools-1.2-core.js"></script>
<script type="text/javascript" src="js/_class.viewer.js"></script>
<script type="text/javascript">//<![CDATA[
window.addEvent('domready',function(){
var V5 = new viewer($('boxCont').getChildren(),{
mode: 'alpha',
fxOptions: {duration:500},
interval: 6000
});
V5.play(true);
});
</script>
<script type="text/javascript">
$(window).load(function () {
// start the slideshow
$('.slideshow').blinds();
})
</script>
如果我禁用mootools,幻灯片工作(反之亦然,使用jQuery)。我试着围绕jQuery.noConflict()包装jQuery;像这样:
If I disable mootools, the slideshow work (vice versa with the jQuery). I tried wrapping the jQuery around jQuery.noConflict(); like so:
<script type="text/javascript">
$.noConflict();
jQuery(document).ready(function($) {
$(window).load(function () {
// start the slideshow
$('.slideshow').blinds();
})
});
</script>
但仍然依赖于mootools的脚本不起作用。请帮忙,因为我不熟悉jQuery / javascript。
But still the mootools dependent script doesn't work. Please help as I'm not really familiar with jQuery/javascript.
谢谢!
推荐答案
一旦调用jQuery.noConflict(),就可以通过jQuery而不是$来引用jQuery。然后,MooTools或其他JavaScript库可以使用$。
Once you call jQuery.noConflict(), you refer to jQuery via jQuery rather than $. $ is then usable by MooTools or another JavaScript library.
<script type="text/javascript">
jQuery.noConflict();
jQuery(document).ready(function() {
jQuery(window).load(function () {
// start the slideshow
jQuery('.slideshow').blinds();
})
});
</script>
如果您想给jQuery另一个名字,您可以执行以下操作:
If you want to give jQuery another name, you can do the following:
<script type="text/javascript">
var jq = jQuery.noConflict();
jq(document).ready(function() {
jq(window).load(function () {
// start the slideshow
jq('.slideshow').blinds();
})
});
</script>
这篇关于JQuery幻灯片和MooTools冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!