0

我只是想添加一个 js 文件,但我无法让它工作......我已经用谷歌搜索但还没有找到任何帮助.. 任何帮助都非常重要

这是我的代码:

<?php

defined('_JEXEC') or die('Restricted access');
jimport('joomla.plugin.plugin');

class plgSystemInfinityScroll extends JPlugin {
protected $_execute;

function __construct(&$subject, $config) {
    $app = JFactory::getApplication();

    if($app->isAdmin())
    {
        return;
    }

    parent::__construct($subject, $config);
    $this->loadLanguage('', JPATH_ADMINISTRATOR);
    $this->_execute = true;
}

public function onBeforeCompileHead() {

    $document =& JFactory::getDocument();
    $document->addScript('/plugins/system/sjdinfinitescroll/jquery.infinitescroll.js');

}

public function onAfterRender() {

}

}
4

1 回答 1

1

首先,Id 使用插件事件:

function onBeforeRender(){

}

其次,您的路径指向错误。

将其更改为:

//J1.6+
$script= JURI::root(true).DS.'plugins'.DS.'system'.DS.'sjdinfinitescroll'.DS.'jquery.infinitescroll.js';
$document =& JFactory::getDocument();
$document->addScript($script);

如果您在同一页面上加载了 MooTools,则必须使用 jQuery.noConflict(); 以避免冲突。

全部一起:

function onBeforeRender(){
      $script= JURI::root(true).DS.'plugins'.
           DS.'system'.DS.'sjdinfinitescroll'.DS.'jquery.infinitescroll.js';
      $document =& JFactory::getDocument();
      $document->addScript($script);
      $document->addScriptDeclaration('jQuery.noConflict();');
      $document->addScriptDeclaration('jQuery(function($){ $('#myid'.append('<h2>my header</h2>');} );');
}
于 2012-05-14T10:05:48.823 回答