在application/helpers/MY_html_helper.php中编写
// ------------------------------------------------------------------------
/**
* scriptSrc
*
* Generates an <script /> element
*
* @access public
* @param mixed
* @return string
*/
if ( ! function_exists('scriptSrc'))
{
function scriptSrc($src = '', $index_page = FALSE)
{
if ( ! is_array($src) )
{
$src = array('src' => $src);
}
$html = '<script ';
foreach ($src as $k=>$v)
{
if ($k == 'src' AND strpos($v, '://') === FALSE)
{
$CI =& get_instance();
if ($index_page === TRUE)
{
$html .= ' src="'.$CI->config->site_url($v).'"';
}
else
{
$html .= ' src="'.$CI->config->slash_item('base_url').$v.'"';
}
}
else
{
$html .= " $k=\"$v\"";
}
}
$html .= ' type="text/javascript"></script>';
return $html;
}
}
---------
默认,不启用html,必须在autoload.php中启用html
----------
使用方式:<?php echo scriptSrc('/a/scripts/index.js'); ?>
生成源代码:
<script src="http://www.edm.q//a/scripts/index.js" type="text/javascript"></script>