难道为了JavaScript的进口有关系吗? [英] Does order of javascript import matter?
问题描述
我有一个aspx页面和进口的jQuery,jTemplate和Flexigrid
I have an aspx page and imports jQuery, jTemplate and Flexigrid
<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script src="Scripts/flexigrid.pack.js" type="text/javascript"></script>
<script src="Scripts/jquery-jtemplates.js" type="text/javascript"></script>
<script src="Scripts/jquery.json-1.3.min.js" type="text/javascript"></script>
请问import语句上述事项的顺序?
Does the order of import statements above matter?
推荐答案
是,如果脚本使用其初始加载过程中由另一个脚本定义的东西。每个脚本加载和评估,从而,同步进行。 (该下载可以并行,如果浏览器希望,但他们会的评估的才能,除非的 延迟
或异步
属性是指定和支持由浏览器。)
Yes, if a script uses anything defined by another script during its initial load. Each script is loaded and evaluated in order, synchronously. (The downloads may be in parallel if the browser wants, but they'll be evaluated in order unless the defer
or async
attributes were specified and are supported by the browser.)
因此,例如,在猜我会说至少在过去的两个脚本使用的第一个脚本所定义的的jQuery
的象征,所以他们必须出现后, ,否则你会看到类似错误的ReferenceError:jQuery是没有定义
So for instance, at a guess I'd say at least the last two scripts use the jQuery
symbol defined by the first script, and so they must appear after it, or you'll see errors like ReferenceError: jQuery is not defined
.
的顺序的无关的脚本并不重要,但在那里建立在彼此(如在这种情况下),它的作用。
The order of unrelated scripts doesn't matter, but where they build on each other (as in this case), it does.
这篇关于难道为了JavaScript的进口有关系吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!