This question already has answers here:
Can I use multiple versions of jQuery on the same page?
                                
                                    (7个答案)
                                
                        
                                5年前关闭。
            
                    
我正在使用此代码弹出模式:

<script src="https://code.jquery.com/jquery-1.10.1.min.js"></script>
<script type="text/javascript" src="/bootstrap.min.js"></script>
<script type="text/javascript">
    $(document).ready(function(){
    $("#btn").click(function(){
        $('#myModal').modal('show');
    });
</script>


并且

<script src="https://code.jquery.com/jquery-1.4.4.1.min.js"></script>


加载在同一页面上而没有冲突。

最佳答案

尝试以这种方式做。加载两个版本的jQuery(不推荐)。然后,将jQuery的全局范围内的变量还原到第一个加载的jQuery。

    <!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>jQuery.noConflict demo</title>
  <script src="//code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>

<div id="log">
  <h3>Before $.noConflict(true)</h3>
</div>
<script src="//code.jquery.com/jquery-1.6.2.js"></script>

<script>
var $log = $( "#log" );

$log.append( "2nd loaded jQuery version ($): " + $.fn.jquery + "<br>" );

// Restore globally scoped jQuery variables to the first version loaded
// (the newer version)

jq162 = jQuery.noConflict( true );

$log.append( "<h3>After $.noConflict(true)</h3>" );
$log.append( "1st loaded jQuery version ($): " + $.fn.jquery + "<br>" );
$log.append( "2nd loaded jQuery version (jq162): " + jq162.fn.jquery + "<br>" );
</script>

</body>
</html>

关于javascript - 同一页面上的两个js库的js冲突,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23571780/

10-12 15:26