CodeIgniter:如何在视图中包括.js文件? [英] CodeIgniter: How do I include a .js file in view?
问题描述
在哪里以及如何在CodeIgniter的Views中包含.js文件?
我尝试过:
< script type = text / javascriptsrc =system / application / libraries / jquery.js>< / script>
因为我认为index.php是加载视图的那个,所以我猜测每次加载一个页面时,当前的dir路径是根,因为index.php位于根。这是真的吗?
上面这行不是这样,我做错了。我有一个CodeIgniter项目。路径如下:
localhost / CodeIgniter / system / application
pre>
所以我应该使用哪个路径来包含位于
中的jquery.js文件
localhost / CodeIgniter / system / application / libraries
位于此处的视图中的jquery.js文件:
localhost / codeIgniter / system / application / views / till_view.php
解决方案这不是index.php 。当您执行
.js 文件可以包含 .js 文件,就像正常的 .html (或 .php )文件:
$ this-> load-> view(viewname)时,
< script src =/ url / to / javascript.js/>
您可能想要创建默认视图或标头视图,其中包含部分或全部(通用) .js 文件。
-CF
Where and how do I include .js files in Views in CodeIgniter?
I have tried this:
<script type="text/javascript" src="system/application/libraries/jquery.js"></script>
As I figured that the index.php is the one that is loading the views, so I'm guessing that every time a page is loaded the current dir path is at root because index.php is located at root. Is this true?
The above line doesn't so I am doing something wrong. I have a CodeIgniter project. The path is like this:
localhost/CodeIgniter/system/application
so which path should I use to include my jquery.js file which is located in
localhost/CodeIgniter/system/application/libraries
when I want to load the jquery.js file in a View located here:
localhost/codeIgniter/system/application/views/till_view.php
解决方案It's not the "index.php" file that is the view. The view is whatever is loaded in your controller when you do a
$this->load->view("viewname");
The file "viewname.php" can then include the .js files, just as a normal .html (or .php) file would:
<script src="/url/to/javascript.js" />
You may want to create a default view or a "header" view that includes some or all of the (common) .js files for your project.
-CF
这篇关于CodeIgniter:如何在视图中包括.js文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!