templette js之后如何包含组件js [英] How can include component js after templete js
问题描述
我在Templete index.php上添加了javascript
I added javascript on templete index.php
$doc = JFactory::getDocument();
$doc->addScript($this->baseurl . '/templates/' . $this->template . '/js/jquery.js', 'text/javascript');
并在下面的组件中添加了另一个
and added another on component below
$document = JFactory::getDocument();
$document->addScript($this->baseurl . '/templates/' . $this->template . '/js/validation.js');
但总是在组件模板(jquery.js)之前添加组件的js(validation.js)
but always js (validation.js) of component getting add before tempelete js(jquery.js)
如何在Templete js(jquery.js)之后添加组件js(validation.js).
How can i add component js(validation.js) after templete js(jquery.js).
推荐答案
如果您将jquery.js
用作项目上的主要jQuery库,则可以简单地将jquery.js
包含在index.php
中的head模块之前.如下所示.
If you are using jquery.js
as main jQuery library on your project then you can simple include the jquery.js
before the head module in index.php
. like below.
<script src="templates/js/jquery.js" type="text/javascript"></script>
<jdoc:include type="head" />
然后在您的组件中只需使用以下内容即可.
Then in your component you can simply use same as below.
$document = JFactory::getDocument();
$document->addScript($this->baseurl . '/templates/' . $this->template . '/js/validation.js');
另一个选项是Addcustom标记,它有助于将脚本添加到文档中.
An alternate option is Addcustom tag , helps to adding scripts to the document.
$document = JFactory::getDocument();
$document->addCustomTag('<script src="'.$this->baseurl . '/templates/' . $this->template . '/js/validation.js" type="text/javascript"></script>');
否则,您还必须以第二顺序在index.php
中加载组件js
,但这将为所有页面加载js
文件.
Otherwise you have to load the component js
also in index.php
with second order but that will load the js
file for all pages.
希望它能提供帮助.
这篇关于templette js之后如何包含组件js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!