codeigniter 加载 javascript

<script src="http://code.jquery.com/jquery-latest.js"></script>
<script src="<?=base_url().'front/js/bootstrap.min.js' ?>"></script>
<script src="<?=base_url()?>front/js/bootstrap.min.js"></script>

1.首先,在.htaccess(位置在网站根目录)文件里设置(作用是隐藏index.php),如下:

RewriteEngine on 
RewriteCond $1 !^(index.php|images|js|img|css|robots.txt) #在这里写要排除的资源等
RewriteRule ^(.*)$ index.php/$1 [L]

2.把JS,CSS,IMG等资源文件夹与SYSTEM文件夹放在同一级下,然后在JS文件夹中建立ajax.js文件,在VIEW层中的文件index.html要引入JS时,如下:

<script type="text/javascript" src="网站绝对URL/js/ajax.js'?>"></script>:注网站绝对URL即 http://localhost/ 

3.在applicationconfigconfig.php文件中设置base_url :

$config['base_url'] =http://www.exiplode/com; //这里是你的网站根目录

4.在contoler构造方法中调用如下代码:

$this->load->helper('url')

5.在VIEW层中具体页面中引入即可:
<script type="text/javascript" src='<?=base_url().'js/Ajax.js'?>'></script>

6.可以使用html的<base href=''<?=base_url()?>"来简化:

<script type="text/javascript" src='js/Ajax.js'></script> 这一点在导入图片时非常有用.


注:“RewriteCond $1 !^(index.php|images|js|img|css|robots.txt) ”的意思是:任意你想访问的资源都不被重定向时,都可写在这里。有时,网站没有加载CSS,JS(它的路径都是正确的)时,都是被重定向了,这要注意.


你可能感兴趣的:(codeigniter 加载 javascript)