How to add and use jquery and css file in joomla module..?

怎甘沉沦 提交于 2019-12-12 02:41:55

问题


$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>
?>

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


回答1:


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

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');


来源:https://stackoverflow.com/questions/4767047/how-to-add-and-use-jquery-and-css-file-in-joomla-module

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!