javascript jQuery/jQueryUI 冲突

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15383126/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 00:36:07  来源:igfitidea点击:

jQuery/jQueryUI conflict

javascriptjquery

提问by sasi

I am using some jquery files for auto complete and datetime picker control but 3 files among them are conflicting:

我正在使用一些 jquery 文件进行自动完成和日期时间选择器控制,但其中 3 个文件存在冲突:

  1. Two files for autocomplete are

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/jquery-ui.min.js"></script>  
    
  2. One file for Calender datetime picker is:

    <script  src="../assets/js/jquery-1.8.3.min.js"></script> 
    
  1. 自动完成的两个文件是

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/jquery-ui.min.js"></script>  
    
  2. 日历日期时间选择器的一个文件是:

    <script  src="../assets/js/jquery-1.8.3.min.js"></script> 
    

These 3 files are confilicting when i comment date time picker file autocomplete works and if I uncomment it autocomplete stops.

当我评论日期时间选择器文件自动完成工作并且如果我取消注释它自动完成会停止时,这 3 个文件是有冲突的。

回答by sasi

If you want to include both the js files you can..

如果你想同时包含这两个 js 文件,你可以......

 <!-- load jQuery 1_8_3 -->
    <script  src="../assets/js/jquery-1.8.3.min.js"></script> 
    <script type="text/javascript">
    var jQuery_1_8_3 = $.noConflict(true);
    </script>

    <!-- load jQuery 1.4.2 -->
    <script type="text/javascript" src="jquery/jquery-1.4.2.js"></script>
    <script type="text/javascript">
    var jQuery_1_4_2= $.noConflict(true);
    </script>

Its better to avoid multiple versions in the page..and its better to use appropriate jquery-UI Version with the jquery version

最好避免页面中的多个版本..最好在 jquery 版本中使用适当的 jquery-UI 版本

回答by Jai

If you try only these, i think you are good to go:

如果你只尝试这些,我认为你很高兴:

<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js">
</script>
<script type="text/javascript" src="http://code.jquery.com/ui/1.10.1/jquery-ui.js">
</script>

No need to add other versions of jquery.

No need to add other versions of jquery.

回答by JohnHeroHD

That's probably because you are including jQuery 2 times. An old version and a newer version.

那可能是因为您包含 jQuery 2 次。一个旧版本和一个新版本。

I would recommend you try and use the most recent versions of both jQuery and jQuery UI and check if everything still works.

我建议您尝试使用 jQuery 和 jQuery UI 的最新版本,并检查一切是否仍然有效。