Joomla!程序中加载JS和CSS的方法

1.加载单独的js文件:

$js = JURI::base().'components/com_foobar/assets/script.js';
$document =& JFactory::getDocument();
$document->addScript($js);


2.加载自定义js函数:

$js = 'function notify(text) { alert(text); }';
$document =& JFactory::getDocument();
$document->addScriptDeclaration($js);


3.加载CSS文件:

$css = JURI::base().'components/com_foobar/assets/style.css';
$document =& JFactory::getDocument();
$document->addStyleSheet($css, 'text/css', 'print');


4.加载CSS片段:

$css = '.somestyle { padding: 10px; }'
$document =& JFactory::getDocument();
$document->addStyleDeclaration($css);
 

以上JS与CSS将加载到Joomla!网页的<head></head>标签内

 

 

更多请看 http://www.solord.com/joomla-15-api.html

你可能感兴趣的:(html,css)