Javascript TYPO3:在“includeJS”包含的javascript之前加载“headerData”包含的javascript
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 
原文地址: http://stackoverflow.com/questions/3551767/
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
TYPO3: get a javascript included by "headerData" to load before one included by "includeJS"
提问by noviolence
I'm loading JQuery into my TYPO3 page by :
我正在通过以下方式将 JQuery 加载到我的 TYPO3 页面中:
page.headerData.10.value = <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
and I'm including my javascript like this :
我像这样包含我的javascript:
page.includeJS {
  file20 = fileadmin/templates/myjq.js
} 
Point is, i need the JQuery to be loaded first. but TYPO3 puts it after my script. How do i get it swapped?
重点是,我需要先加载 JQuery。但是 TYPO3 把它放在我的脚本之后。我如何得到它交换?
Thanks
谢谢
回答by DerSchreiner
you don't want to include JQuery that way; Use
您不想以这种方式包含 JQuery;用
page.includeJSlibs.jquery.external = 1
page.includeJSlibs.jquery = //ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js
instead.
反而。
http://typo3.org/documentation/document-library/core-documentation/doc_core_tsref/4.3.2/view/1/6/
http://typo3.org/documentation/document-library/core-documentation/doc_core_tsref/4.3.2/view/1/6/
EditUsing a URL without a specific protocol (http or https) makes sure the inclusion works on both SSL and non-SSL-sites.
编辑使用没有特定协议(http 或 https)的 URL 可确保包含适用于 SSL 和非 SSL 站点。
回答by Tillebeck
Small add-on to Patrick Schriner to include all js-files in one go. It will also make sure selected files are loaded first.
Patrick Schriner 的小插件,一次性包含所有 js 文件。它还将确保首先加载选定的文件。
You can add a line (forOnTop) to force your jQuery to be included on top. Else javascript more often seems to be included last to speed up the load of the page. In this example I include several files. Specific for the jQuery is the jQuery[forceOnTop] to ... well, selv explaining I guess.
您可以添加一行 (forOnTop) 以强制您的 jQuery 包含在顶部。其他 javascript 似乎更常被包含在最后以加快页面的加载速度。在这个例子中,我包含了几个文件。特定于 jQuery 的是 jQuery[forceOnTop] 到......好吧,我猜是 selv 解释。
includeJS {
   1 = fileadmin/templates/website/scripts/javascript.js
   2 = EXT:ogelementslide/res/jquery.easing.1.3.js
   3 = EXT:ogelementslide/res/jquery.easing.compatibility.js
   4 = EXT:ogelementslide/res/jquery.bxSlider.min.js
   jquery = http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js
   jquery.external = 1
   jquery.forceOnTop = 1
}
Please notice that the numbers 1-4 and jQuery are equivalent. I could have written 5 instead of jQuery. In that case it would have been:
请注意数字 1-4 和 jQuery 是等价的。我本可以写 5 而不是 jQuery。在那种情况下,它会是:
includeJS {
   1 = fileadmin/templates/website/scripts/javascript.js
   2 = EXT:ogelementslide/res/jquery.easing.1.3.js
   3 = EXT:ogelementslide/res/jquery.easing.compatibility.js
   4 = EXT:ogelementslide/res/jquery.bxSlider.min.js
   5 = http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js
   5.external = 1
   5.forceOnTop = 1
}
BR. Anders
BR。安德斯
回答by Rito
page.headerData.10 = TEXT    
page.headerData.10.value (
     <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
     <script type="text/javascript" src="fileadmin/templates/myjq.js"></script>
    )
and yes you need round braces here :) Instead of TEXT you can also use HTML.
是的,您在这里需要圆括号 :) 您也可以使用 HTML 代替 TEXT。
edit: you can also do it like this
编辑:你也可以这样做
page.headerData.10.value = <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
page.headerData.20.value = <script type="text/javascript" src="fileadmin/templates/myjq.js"></script>

