2011-01-29 72 views
2

我有一个全新的codeigniter 2.0安装,我很难连接外部JavaScript文件。下面是我有:codeigniter外部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不。我究竟做错了什么?

+0

当你键入JavaScript网址到地址栏,请问脚本负荷? – Pointy 2011-01-29 20:04:54

回答

2
<script source="http://localhost/JS/javascript.js" type="text/javascript"></script> 

应该是:

<script src="http://localhost/JS/javascript.js" type="text/javascript"></script> 

SRC,而不是源