$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 文件,但那一行不显示。
最佳答案
$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');
关于jquery - 如何在 joomla 模块中添加和使用 jquery 和 css 文件..?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4767047/