您的位置:首页 > Web前端 > JQuery

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

2016-04-19 09:51 519 查看
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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: