为什么我需要两次加载 jquery [英] Why do I need to load jquery twice

查看:45
本文介绍了为什么我需要两次加载 jquery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 html 页面中,我需要将 jquery 放入两次.如果我将其中任何人从我的页面中取出,则该页面不会被呈现.请注意,包含的jquery"都指向相同的位置.

In my html page, I need to put jquery twice. If I take anyone of them out my page , then the page does not get rendered. Kindly note that both the included "jquery" are pointing to same location.

我正在使用backbone.js.我添加了 require.js 以在页面底部包含 jquery.另外,我需要在页面的开头添加 jquery.一旦我添加了这两个,我的整个页面就会正确呈现.如果我把它们中的任何一个拿出来,我就会开始遇到问题.

I am using backbone.js. I have added require.js to include jquery at the bottom of the page. Also, I need to add jquery at the start of the page. Once I add these two, then my whole page renders properly. If I take any of them out I start getting issues.

有人能解释一下为什么会发生这个问题吗.

Can someone throw some light on why this issue is happening.

在页面的HEAD标签中添加的脚本:

Script added in the HEAD tag of page:

 <script src="../vendors/jquery/dist/jquery.min.js"></script>

BODY底部添加的脚本:

Script added in BODY bottom:

<script type="text/javascript">
require(['common'],function()
{
  require(['jquery', 'fastclick','nprogress','charts','underscore'],function()
  {
    require(['firstDashboardController']);
  });
});
</script>

如果我使用包含在下面页面顶部的 jquery 是我得到的错误:

If I take the jquery included at the top of the page below is the error I get:

如果我从底部的 require 模块中取出 jquery,则错误如下:

If I take the jquery out of require module at the bottom, then below is the error:

P.S:我使用chart.js 一个外部文件在页面上绘制图形和内容.

P.S: I am using chart.js an external file to draw graph and stuff on the page.

推荐答案

这个问题的一个常见解决方案是使用 jQuery 的内置 $.noConflict(true) 但我建议你在您的底部

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆