如何在joomla模块中添加和使用jquery和css文件..?

时间:2011-01-22 09:11:23

标签: jquery css module joomla1.5

$document = &JFactory::getDocument();//getting document ref object
$document->addScript(JURI::root() . 'modules/mod_my_slider/jquery.js');

$path = "http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']."modules/mod_my_slider/images";
$path = str_replace("index.php","",$path);
?>
<script language="javascript">
  jQuery('#block').show();
 </script>
 <center>
 <div height:220px; width:500px; border:1px solid black;>
  <img class="slide" height="220px" width="500px" src="<?php echo $path; ?>/pier1.jpg"/>
 </div>
 <div id="block" style="height:100px; width:10px; display:none; background-color:white;">BETA</div>
 </center>
?>

我尝试上面,我也包括jquery文件,但该行不显示。

1 个答案:

答案 0 :(得分:0)

$document =& JFactory::getDocument();
$document->addScript($url);
$document->addStyleSheet($url);

这绝对是将jscript和CSS添加到模块的正确语法。我能看到的唯一问题是,如果使用安装程序,Joomla会自动将JS文件放在modules / module_name / js和CSS中的modules / module_name / css文件夹中。如果该行根本没有那么你有另一个问题,如果该行但是没有添加该文件,你可能需要将代码更改为

$document->addScript(JURI::root() . 'modules/mod_my_slider/js/jquery.js');