如何在CodeIgniter中包含jQuery文件? [英] How do I include jQuery file in CodeIgniter?

查看:105
本文介绍了如何在CodeIgniter中包含jQuery文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的CodeIngiter项目中使用jQuery。我不知道如何包含js文件。

I would like to use jQuery inside my CodeIngiter Project. I dont know how to include the js file.

我想在我的视图中有下面的东西

I would like to have something like below in my view

<script src='<?php echo base_url().APPPATH ?>js/jquery.js'></script>
<script src='<?php echo base_url().APPPATH ?>js/my-js.js'></script>


推荐答案

Codeigniter有一个javascript类: http://codeigniter.com/user_guide/libraries/javascript.html

Codeigniter has a javascript class: http://codeigniter.com/user_guide/libraries/javascript.html

您将通过以下方式加载jquery库:

You would load the jquery library through:

$this->load->library('jquery');

然后,您可以将其粘贴到视图的头部分:

Then you can paste this into your head section of your view:

<?php echo $library_src;?>
<?php echo $script_head;?>

对于其他javascript文件,我通常在我的应用程序文件夹中创建一个资源文件夹,然后使用base_url函数链接到以下文件:

For additional javascript files, I typically create a resource folder in my application folder, then use the base_url function to link to the files like:

<script src="<?php echo base_url('resources/name-of-js-file.js');?>" type="text/javascript"></script>

这篇关于如何在CodeIgniter中包含jQuery文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆