Two jQuery object conflict

2019-08-27 17:46发布

I'm having this problem, I can't get to work two jQuery based objects on my page. According to placement, on or other doesn't seem to work properly.

Codes looks about this at the moment :

   <script type="text/javascript" src="jquery-1.2.6.min.js"></script>
    <script type="text/javascript" src="jquery-ui-personalized-1.5.2.packed.js"></script>
    <script type="text/javascript" src="sprinkle.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
    <script src="js/slides.min.jquery.js"></script>

    <script>
        $(function(){
            $('#slides').slides({
                preload: true,
                generateNextPrev: false
            });
        });

    </script>

I'm out of options, any ideas how to get these guys to work together?

1条回答
我欲成王,谁敢阻挡
2楼-- · 2019-08-27 18:03

You're really not supposed to use two jQuery versions together at the same time, but if you must:

<script type="text/javascript" src="jquery-1.2.6.min.js"></script>
<script>
    $jq1 = $.noConflict(true);
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script>
    $jq2 = $.noConflict(true);
</script>

Now you have the 1.2.6 version as $jq1 and the other as $jq2:

$jq1(function(){
        $jq1('#slides').slides({
            preload: true,
            generateNextPrev: false
        });
    });
查看更多
登录 后发表回答