2011-08-07 57 views
0

我已经被困在这个大约一个小时。我有下面的代码,页面加载时不加载alert框。jQuery警告框不会出现

我尝试过两种不同的机器,但无济于事(两台机器上都使用JS和Chrome和FF)。

<!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" /> 
    <title><?php echo $pageTitle; ?></title> 

    <link href="../css/style.css" rel="stylesheet" type="text/css" media="all" /> 
    <link href="/favicon.ico" rel="shortcut icon" type="image/x-icon" /> 
    <!--[if !IE 7]> 
    <style type="text/css"> 
     #wrap {display:table;height:100%} 
    </style> 
    <![endif]--> 

    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script> 
    <script type="text/javascript"> 
    $(document).ready(function() { 
     alert("hello"); 
    } 
    </script> 
</head> 

<body> 
    ... 
</body> 
</html> 

回答

8
$(document).ready(function() { 
    alert("hello"); 
});      //note this line 
+2

了一个小时花了,我会设法清除关闭标签剥离一切了..另一个幸福深夜编码包裹。谢谢:) – lethalMango

3

你错过了你的右括号和分号:

<script type="text/javascript"> 
    $(document).ready(function() { 
     alert("hello"); 
    }); 
    </script> 
3

本替换你的脚本:

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script> 
    <script type="text/javascript"> 
     $(document).ready(function() { 
      alert("hello"); 
     }); 
    </script> 

出于某种原因,你不能关闭只需使用/>关闭脚本标记。你需要一个关闭元素。你也错过了jquery ready函数的右括号。

+0

我刚刚读了关于结束标签的另一个答案 - 谢谢:) – lethalMango

2

you miss closing);在标签之前

0

无法以简短的方式关闭<script>标签,您需要使用<script></script>。此外jQuery的包装需要与

$(document).ready(function() { 
    ... 
}); 

或只是

$(function(){ 
    ... 
});