【问题标题】:load js file to view in ci bonfire加载js文件以在ci bonfire中查看
【发布时间】:2013-10-28 12:07:05
【问题描述】:

我有一个模块调用ftp_data。我的模块资产文件夹bonfire/modules/ftp_data/assets/js/ftp_data.js 中还有一个 js 文件。 现在我想将此文件加载到我的视图中

内部视图

<!-- Edit by Yesh -->
<div class="container-fluid">
    <form method="POST" id="url_finder" name="url_finder">
        <div class="span4">
            <h3>Search URL : <input type="search" id="search_url" name="search_url" placeholder="www.example.com"></h3>
        </div>
        <div class="span3">
            <button id="url_btn" name="url_btn" class="btn" type="submit">Search</button>
        </div>
    </form>
</div>
<!-- Edit by Yesh -->

在 ftp_data.js 中

$(function(){
    $('#search_url').keyup(function(){
        var s = new RegExp(this.value.toLowerCase());
        $('.result_table .result_row').each(function() {
            if(s.test(this.innerHTML.toLowerCase())){
                $(this).show();
            }else{
                $(this).hide();
            }
        });
    });
});

【问题讨论】:

  • 请投票。如果你从中得到一些东西

标签: javascript php bonfire


【解决方案1】:

要在 View 模块中加载 js/css 文件,您应该使用构造函数方法。您可以简单地复制我在下面添加的代码。

代码如下:

 public function __construct()
    {
        parent::__construct();
        Assets::add_module_js('ftp_data', 'ftp_data.js');
    }

add_module_js():第一个参数定义要使用的模块的名称,第二个参数定义要加载的文件。

【讨论】:

    【解决方案2】:

    将此代码放在您的视图文件中

    <script src="assets/js/ftp_data.js"></script>
    

    【讨论】:

    • 我这样做了。当我这样做时,这个 ftp_data.js 文件在 jquery.min.js 文件之前加载。所以,在那种情况下,这个文件不支持
    【解决方案3】:

    我终于找到了解决方案。这就是我发现的。希望对你也有帮助。

    public function index()
    {
    //---functions will goes here
    //--Add this code before closing public function index
    Assets::add_module_js('ftp_data', 'ftp_data.js');
    //--ftp_data is the Module name. 
    //--ftp_data.js is the name of the js file that is inside the module/assets/js/
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-05-19
      • 2016-01-28
      • 1970-01-01
      • 2021-05-01
      • 2016-09-26
      • 2017-09-02
      • 1970-01-01
      相关资源
      最近更新 更多