如何在Codeigniter控制器中使用JavaScript

时间:2018-08-08 16:25:22

标签: javascript codeigniter methods controller protected

js_class.php

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class js_class extends CI_Controller
{
    public function __construct() {
        parent::__construct();
        $this->load->library('javascript');
        $this->load->library('javascript/jquery');

        $this->load->library('session');
        $this->load->helper(array( 'form', 'url' ));
        $this->load->helper('url');
        $this->load->database();
        $this->load->library('form_validation');

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


    }


    public function index() {
        $data['library_src'] = $this->jquery->script();
        $data['click'] = $this->jquery->_click('#click', "alert('Hello! You Click the button');");


        $this->load->view('js_class_view', $data);
    }
}

?>

config.php

$config['javascript_location'] = 'http://localhost/test/assets/js/jquery.min.js';

当我编译代码时,发生错误,该错误表示对受保护方法CI_jquery::_click()的调用。如果您已解决此类问题,请帮助我

1 个答案:

答案 0 :(得分:0)

请更正此代码

$ data ['click'] = $ this-> jquery-> _ click('#click',“ alert('Hello!You Click the button')”);

删除“;”在此“警报('Hello!您单击按钮');”上代码