2014-04-03 70 views
-1

我得到以下錯誤:Uncaught SyntaxError: Unexpected end of input線路1意外結束,jQuery的

下面是代碼:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<link rel="stylesheet" type="text/css" href="./styles/default.css" /> 
<script src="./scripts/global.js"></script> 
<script src="./scripts/jquery.js"></script> 
<script> 
$(document).ready(function() { 
var array = [ 'body_bg_2','body_bg_3','body_bg_4','body_bg_5' ]; 
    var selected = array[Math.floor(Math.random() * array.length)]; 
    $('<img src="./assets/'+selected+'.gif">').load(function() { 
     $(this).appendTo('body'); 
    }); 
} 
</script> 
<title>Cats!</title> 
</head> 

我不明白是什麼問題?任何人都知道解決方案?

+2

),你錯過了至少一個')'在腳本的結尾。由'.ready(' –

+1

)打開。這個問題似乎是無關緊要的,因爲它是關於語法錯誤的。Stackoverflow不是一個調試幫助臺。 –

回答

4

你缺少關閉您的文檔準備處理

使用

<script> 
$(document).ready(function() { 
var array = [ 'body_bg_2','body_bg_3','body_bg_4','body_bg_5' ]; 
    var selected = array[Math.floor(Math.random() * array.length)]; 
    $('<img src="./assets/'+selected+'.gif">').load(function() { 
     $(this).appendTo('body'); 
    }); 
}); //<== Here you have missed) 
</script> 
1
$(document).ready(function() { 
    var array = [ 'body_bg_2', 'body_bg_3', 'body_bg_4', 'body_bg_5' ]; 
    var selected = array[Math.floor(Math.random() * array.length)]; 
    $('<img src="./assets/' + selected + '.gif">').load(function() { 
     $(this).appendTo('body'); 
    }); 
}); /* <--- this is your fail */