意外结束输入,jquery

时间:2014-04-03 13:04:04

标签: javascript jquery html

我收到以下错误:第1行Uncaught SyntaxError: Unexpected end of input

以下是代码:

<!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 个答案:

答案 0 :(得分: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 :(得分: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 */