如何在joomla模块中添加和使用jquery和css文件? [英] How to add and use jquery and css file in joomla module..?

查看:448
本文介绍了如何在joomla模块中添加和使用jquery和css文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$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文件,但该行不显示。

I try like above,i also include file of jquery but that line not display.

推荐答案

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

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

This is definitely the correct syntax for adding jscript and CSS to a module. The only issue I can see is that Joomla automatically puts JS files in modules/module_name/js and CSS in modules/module_name/css folders if you use the installer. If the line is not there at all then you have another issue, if the line is there but the file is not added, you probably need to change your code to

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

这篇关于如何在joomla模块中添加和使用jquery和css文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆