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/