2014-01-09 12 views
2

後,我加入的JavaScript上templete的index.php如何可以包括組件JS templete的js

$doc = JFactory::getDocument(); 
$doc->addScript($this->baseurl . '/templates/' . $this->template . '/js/jquery.js', 'text/javascript'); 

和成分的添加另一對組件的下方

$document = JFactory::getDocument();  
$document->addScript($this->baseurl . '/templates/' . $this->template . '/js/validation.js'); 

但總是JS(validation.js)獲得添加之前tempelete js(jquery.js)

如何添加組件js(validation.js)在模仿js(jquery.js)之後。

回答

1

如果您在項目中使用jquery.js作爲主jQuery庫,那麼您可以在index.php的頭部模塊之前簡單包含jquery.js。如下所示。

<script src="templates/js/jquery.js" type="text/javascript"></script> 
<jdoc:include type="head" /> 

然後在你的組件中,你可以簡單地使用下面的相同。

$document = JFactory::getDocument();  
$document->addScript($this->baseurl . '/templates/' . $this->template . '/js/validation.js'); 

另一種選擇是Addcustom標籤,有助於向文檔添加腳本。

$document = JFactory::getDocument(); 
$document->addCustomTag('<script src="'.$this->baseurl . '/templates/' . $this->template . '/js/validation.js" type="text/javascript"></script>'); 

否則,你有第二順序加載組件jsindex.php但將加載js文件的所有頁面。

希望它有助於..

1

我會通過谷歌,發現一個解決方案,我可以使用自定義標籤功能部件如下圖所示:

$document = JFactory::getDocument(); 
$document->addCustomTag('<script src="'.$this->baseurl . '/templates/' . $this->template . '/js/validation.js" type="text/javascript"></script>'); 

和模板下方:

$doc = JFactory::getDocument(); 
$doc->addScript($this->baseurl . '/templates/' . $this->template . '/js/jquery.js', 'text/javascript') 
+0

尼斯..你也可以使用這種方法,如果腳本文件只有有限的行你可以使用addScriptDeclaration也檢查這個http://docs.joomla.org/Adding_JavaScript –