如何在joomla组件中包含css和jquery

时间:2014-01-03 07:06:30

标签: php jquery css joomla

我将一些jquery和css添加到joomla组件文件view / edit / tmpl / default.php中。我知道我需要使用jdoc include,但这样做的步骤是什么?我应该把它放在哪里 jdoc:包含

代码是这样的。

<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');

 $row = $this->row;
?>

<div class="componentheading" style="margin-bottom:10px;">Edit Event</div>

<form id="form" method="post" action="index.php?option=com_event&view=save" >

        <table >
                    <tr>
                            <td>Title</td>
<td><input type="text"     name="title" value="<?php echo $row->title;?>"></td>
                    </tr>

                    <tr>
                            <td>Start Time</td>
   <td><input type="text" name="from" value="<?php echo $row->from;?>" id="datetimepicker"></td>
                    </tr>
</form>

需要包含的文件

-jquery.datetimepicker.css
-jquery.datetimepicker.js
-jquery.js

2 个答案:

答案 0 :(得分:3)

你能试试吗,

 $document =& JFactory::getDocument();
 $document->addStyleSheet('your css url here ');// for css
 $document->addScript('your jaavscript url here ');// for script

参考:http://docs.joomla.org/J3.2:Adding_JavaScript_and_CSS_to_the_page

答案 1 :(得分:1)

由于jQuery包含在Joomla 3中,因此您可以在视图中使用以下代码来包含jQuery

JHtml::_('jquery.framework');

对于CSS部分,请使用以下传统方法

/**
 * Notice only = instead of &=
 *
 */
$doc = JFactory::getDocument();
$doc->addStyleSheet(JURI::root(true) . '/your/css/path/here');

JHTML::stylesheet('/your/css/URL/here');