Jquery库在一个页面中添加两次时出现问题


Jquery library issues while adding twice in a page

我正在使用Adminlte主题。这里我有用于主题的J个查询库。我已经在页脚添加了它。如果我在标题中添加它,它会导致UI出现问题。我的问题是我有ajax加载的页面,我需要一些库(也在页脚中)来包含在那里。如果没有,它就不会起作用。

现在,如果我在没有刷新页面的情况下加载ajax页面后返回,问题就在那里。问题是由于在一页中加载库两次。我该怎么办?

更改加载jQuery的方式,使其仅在尚未加载到dom中时加载:

<script type="text/javascript">
if(!window.jQuery){
   var script = document.createElement('script');
   script.type = "text/javascript";
   script.src = "jquery.js";
   document.getElementsByTagName('footer')[0].appendChild(script);
}
</script>

我假设您的文档中有一个页脚html标记,否则使用document.getElementById("footer")[0].appendChild(script);将脚本附加到#footer标记。

对于这种问题,我使用一个POST或GET变量由footer.php的ajax函数传递,因此它希望加载我不想的任何库

查看我的Footer.php

<?php
if(empty($_GET['load_lib']){
?>
<script src=" path to the js file"></script>
<? }else{
//no files to be loaded
} ?>

在Ajax函数中,我将load_lib作为参数传递,其值为"yes"或"true"等。。。祝你好运。。。