Two jQuery object conflict

拈花ヽ惹草 提交于 2019-12-25 09:30:15

问题


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:


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
        });
    });


来源:https://stackoverflow.com/questions/14593753/two-jquery-object-conflict

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!