【问题标题】:How to include css and jquery in joomla component如何在 joomla 组件中包含 css 和 jquery
【发布时间】:2014-01-20 19:31:29
【问题描述】:

我将一些 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

【问题讨论】:

    标签: php jquery css joomla


    【解决方案1】:

    你可以试试这个,

     $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

    【讨论】:

    • 我不太明白 & JFactory::getDocument(); 背后的逻辑你能解释一下吗?谢谢!
    【解决方案2】:

    由于 Joomla 3 中包含 jQuery,您可以在要包含 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');
    

    【讨论】:

      猜你喜欢
      • 2011-04-15
      • 1970-01-01
      • 2013-01-21
      • 2013-08-28
      • 1970-01-01
      • 1970-01-01
      • 2011-02-22
      • 2020-11-17
      • 2015-09-22
      相关资源
      最近更新 更多