Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 外部资源仅在JSFiddle-Bootbox/jQuery中工作_Javascript_Jquery_Twitter Bootstrap_Jsfiddle_Bootbox - Fatal编程技术网

Javascript 外部资源仅在JSFiddle-Bootbox/jQuery中工作

Javascript 外部资源仅在JSFiddle-Bootbox/jQuery中工作,javascript,jquery,twitter-bootstrap,jsfiddle,bootbox,Javascript,Jquery,Twitter Bootstrap,Jsfiddle,Bootbox,当“Frameworks&Extensions”设置为jquery2.0.2时,提示会起作用 但是当我加上 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script> …为了替换JSFiddle的jQuery 2.0.2,我将“Frameworks&Extensions”设置回“No Library(pure JS)”,提示符不再起作用 在尝试了几十

当“Frameworks&Extensions”设置为jquery2.0.2时,提示会起作用 但是当我加上

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>

…为了替换JSFiddle的jQuery 2.0.2,我将“Frameworks&Extensions”设置回“No Library(pure JS)”,提示符不再起作用


在尝试了几十种变体之后,提示符仍然无法运行。是什么导致了这种行为上的差异?

因为这样做时,加载JS文件的顺序是不同的。引导和其他文件在jQuery文件之前加载。因此,当它查找文件时,它不在那里并抛出一个错误。看看控制台。

问题是在加载jQuery之前加载了引导外部库(如果您不想让它通过JSFIDLE接口和HTML页面加载),而引导需要jQuery已经加载才能初始化

ie:如果你引导工作,这不能在HTML部分

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.js"></script>

我已经用正确的顺序更新了你的小提琴:

http://jsfiddle.net/gjkooofv/13/


请注意,在外部库中,jquery是第一个,然后是所有其他库。

这是由于JSFIDLE在输出页面中“插入”代码的方式造成的

您的小提琴使用4种方式输入代码:

  • HTML框(左上角)
  • CSS框(右上角)
  • JavaScript框(左下角)和
  • “外部资源”(左菜单)
输出部分(右下角)将打印您在上述框中放置的内容,如下所示:

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <title> - jsFiddle demo by Birdlaw</title>

    <!-- Here goes the selected JS lib (jQuery 2.0.2 in your example) -->

    <!-- Selected Extensions are here (in your case, bootstrap, then bootbox) -->

    <style type="text/css">
    <!-- Content of the CSS (top right) box goes here -->
    </style>

    <script type="text/javascript">//<![CDATA[
    $(window).load(function(){

    //<!-- Content of the JavaScript (bottom left) box goes here -->
    //<!-- Actually, this can be configured (the second combo at left menu - "onLoad") -->

    });//]]> 
    </script>
</head>
<body>
    <!-- Content of the HTML box goes here -->
</body>
</html>

-Birdlaw的JSFIDLE演示
//
//
});//]]> 
如您所见,将jQuery从所选框架中取出并放入HTML框中会产生不同的结果

选择它作为框架将其放置在扩展(引导和引导盒)文件之前。当它位于HTML框中时,它被放置在扩展文件之后,从而产生错误(因为这些文件需要jQuery)

如何使其工作?如果您想“手动”将jQuery放在HTML框中,那么请将所有扩展文件也按正确的顺序放在那里。这将使它按预期工作

这是上面的一张照片