如何在模板 js 之后包含组件 js [英] How can include component js after templete js

查看:12
本文介绍了如何在模板 js 之后包含组件 js的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 tempte 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');  

但总是在模板 js(jquery.js) 之前添加组件的 js (validation.js)

but always js (validation.js) of component getting add before tempelete js(jquery.js)

如何在模板 js(jquery.js) 之后添加组件 js(validation.js).

How can i add component js(validation.js) after templete js(jquery.js).

推荐答案

如果您在项目中使用 jquery.js 作为主要 jQuery 库,那么您可以简单地包含 jquery.jsindex.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 tag ,有助于将脚本添加到文档中.

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.

希望它有所帮助..

这篇关于如何在模板 js 之后包含组件 js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆