javascript - 当我在 codeigniter 中使用 jquery 发出警报时没有任何反应

标签 javascript php jquery codeigniter

Jquery/Javascript 无法在 codeigniter 中工作。我所做的是

config.php中我包含

$config['javascript_location'] = 'libraries/javascript/jquery.js';
$config['javascript_ajax_img'] = 'images/ajax-loader.gif';

controller/welcome.php 中我包含

public function __construct()
    {
        parent::__construct();
        $this->load->library('javascript');
        $this->load->library('javascript/jquery');
    }
    public function index()
    {
        $data['library_src'] = $this->jquery->script();
        $data['script_head'] = $this->jquery->_compile();

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

views/register.php中我包括

<?php $this->jquery->click('#username', $this->jquery->alert("hi")); ?> 

但是什么也没发生。没有显示错误。如何在 Codeigniter 中创建 jquery/Javascript 事件。其他人提出了与此相关的问题,但我还找不到解决方案。因此,不要将其标记为重复。

谢谢。

编辑

在 CI 中使用 jquery 的任何替代方式(任何方式)。简单地说,我如何在 CI 中使用 jquery。

最佳答案

我建议您使用 jQuery 作为 javascript,而不是使用 codeigniter 中包含的版本,因为它可能是旧版本,您可以使用,但您的 javascript 库位于项目根目录下名为 asset/js 的新文件夹中

并将它们包含在 View 中,如下所示

<html>
     <head>
          <script src="<?=base_url()?>/assets/js/jquery.js" type="text/javscript"></script>
<script>
     $(document).ready(function(){
          $("#username").click(function(){
               //your code here
          });
     });
</script>
     </head>

关于javascript - 当我在 codeigniter 中使用 jquery 发出警报时没有任何反应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24114280/

相关文章:

javascript - Node.js 测量多个请求的响应时间

php - 用 PHP 安全地发送多封电子邮件

javascript - 使用 PHP 和 JS 更新表单值

javascript - 使用 Javascript 通过 AJAX 从 URL 获取 JSON 响应

javascript - AngularJS 用 Canvas 写在图像上

javascript - 使用 d3.js 的维恩图布局

javascript - jQuery:具有相同名称的项目/类

php - 无法添加或更新子行外键约束失败 mysql 错误号 : 1452

javascript - 在 jQuery 中继续之前等待动画完成

javascript - 如何检查页面是否存在垂直滚动条?