CodeIgniter: How do I include a .js file in view?

前端 未结 7 955
粉色の甜心
粉色の甜心 2020-12-30 12:38

Where and how do I include .js files in Views in CodeIgniter?

I have tried this:



        
相关标签:
7条回答
  • 2020-12-30 13:44

    First question:

    It depends if you use absolute or relative urls.

    Absolute urls go from the root of your domain. Relative urls are loaded relative from the current directory (including the url segments).

    Second question: It's best to use an absolute URL. Because of the pretty urls, it's not recommended to use relative urls.

    The easiest way is to use the url helper and then use the site url function like this:

    $this->load->helper('url');
    echo site_url('system/application/libraries/jquery.js');
    

    Ps. I recommend to put things like javascript and images outside of the CodeIgniter directory.

    0 讨论(0)
提交回复
热议问题