jquery类库和其他js类冲突的解决方法

转自:http://www.w3ci.com/front/jQuery/431.html

今天做项目的时候同一页面两效果发生冲突,经观察发现是prototype和jquery冲突了。

prototype的选择器是"$"

jquery的选择器也是"$"

解决方法是:

将jquery的"$"改为其他的,如"$j"。

先将所有需要导入的js导入后,再在运行脚本处,加上一行:$j = jQuery.noConflict();

其后将其所用特效的所有"$"都改为"$j"

问题解决。
 

<script language="javascript" type = "text/javascript" src="content/script/prototype.lite.js"></script>
<script language="javascript" type = "text/javascript" src="content/script/moo.fx.js"></script>
<script language="javascript" type = "text/javascript" src="content/script/moo.fx.pack.js"></script>
<script language="javascript" type = "text/javascript" src="content/script/jquery-1.2.6.min.js"></script>
 
<script type="text/javascript">
    $j = jQuery.noConflict();
    function slideSwitch() {
        var $jactive = $j('#slideshow IMG.active');
 
        if ($jactive.length == 0) $jactive = $j('#slideshow IMG:last');
 
        // use this to pull the images in the order they appear in the markup
        var $jnext = $jactive.next().length ? $jactive.next()
        : $j('#slideshow IMG:first');
 
        // uncomment the 3 lines below to pull the images in random order
 
        // var $sibs  = $active.siblings();
        // var rndNum = Math.floor(Math.random() * $sibs.length );
        // var $next  = $( $sibs[ rndNum ] );
 
 
        $jactive.addClass('last-active');
 
        $jnext.css({ opacity: 0.0 })
        .addClass('active')
        .animate({ opacity: 1.0 }, 1000, function() {
            $jactive.removeClass('active last-active');
        });
    }
 
    $j(function() {
        setInterval("slideSwitch()", 4000);
    });
    </script>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值