多个jQuery包含在文档中

bah*_*bah 5 javascript jquery

我有一个使用旧jQuery的文档,我需要新的jQuery用于特定的插件.我的文档结构如下所示:

<html>
<head>
    <script type="text/javascript" src="jQuery.old.js"></script>
</head>
<body>
    <script>
        $("#elem").doSomething(); // use old jQuery
    </script>            
    <!-------- My plugin begins -------->
        <script type="text/javascript" src="jQuery.new.js"></script>
        <script type="text/javascript" src="jQuery.doSomething.js"></script>
        <script>
        $().ready(function(){
            $("#elem").doSomething();   // use new jQuery
        });
        </script>
        <div id="elem"></div>
    <!-------- My plugin ends ---------->
    <script>
        $("#elem").doSomething(); // use old jQuery
    </script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

我已经搜索了这个问题,但没有发现任何看起来像我的情况(我需要先加载旧的javascript(在头部)和那么新的(在正文中).顺便说一句,在Firefox中看起来像旧的jQuery lib加载和依赖它的脚本有效,但是使用新版本的脚本,在IE和Chrome中,一切都正好相反.

Fen*_*ton 13

首先,您应该尝试在最新版本的jQuery下运行所有​​插件 - 您可能会发现只能使用一个最新版本.

如果无法执行此操作,则可以在兼容模式下运行.这是怎么回事.

<script src="jquery-1.3.2.js"></script>
<script>
    var jqueryA = jQuery.noConflict();
</script>
<script src="jquery-1.4.2.js"></script>
<script>
    var jqueryB = jQuery.noConflict();
</script>
Run Code Online (Sandbox Code Playgroud)

你需要打电话

jqueryB("#myelement").....
Run Code Online (Sandbox Code Playgroud)

使用备用版本.