codeigniter 外部 javascript
我全新安装了 codeigniter 2.0,但在链接外部 javascript 文件时遇到了困难。这是我所拥有的:
我的控制器:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Welcome extends CI_Controller {
function __construct()
{
parent::__construct();
}
function index()
{
$this->load->view('welcome_message');
}
}
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */
我的视图:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Welcome to CodeIgniter</title>
<script source="http://localhost/JS/javascript.js" type="text/javascript"></script>
</head>
<body>
<A HREF="javascript:a_message()">Click for a message..</A>
<img src="http://localhost/images/apache_pb.png" >
</body>
</html>
我的Javascript:
function a_message(){ alert('yay'); }
目录结构:
htdocs
application
images
apache_pb.png
JS
javascript.js
system
user_guide
xampp
index.php
license.txt
Thumbs.db
为了简单起见,我在我的路径中使用“http://localhost...”。图像已加载,但 javascript 未加载。我做错了什么?
I have a fresh install of codeigniter 2.0, and I'm having a hard time linking external javascript files. Here's what I have:
My controller:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Welcome extends CI_Controller {
function __construct()
{
parent::__construct();
}
function index()
{
$this->load->view('welcome_message');
}
}
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */
My view:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Welcome to CodeIgniter</title>
<script source="http://localhost/JS/javascript.js" type="text/javascript"></script>
</head>
<body>
<A HREF="javascript:a_message()">Click for a message..</A>
<img src="http://localhost/images/apache_pb.png" >
</body>
</html>
My Javascript:
function a_message(){ alert('yay'); }
Directory structure:
htdocs
application
images
apache_pb.png
JS
javascript.js
system
user_guide
xampp
index.php
license.txt
Thumbs.db
I'm using "http://localhost..." in my paths here for simplicity. The image loads, but the javascript doesn't. What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
应该是:
src,而不是源
should be:
src, not source