2011-01-29 70 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,而不是源