开发者

jQuery alert box doesn't appear

I have been stumped on this for about an hour. I have the following code that doesn't load the alert box when the page loads.

I have tried on two different machines with no avail (JS is enabled on both machines using both Chrome and 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>


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


You're missing your closing parenthesis and semi-colon:

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


Replace your script with this:

  <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>

For some reason you can't close the script tag with just a /> to close. You need a closing element. Also you are missing the closing bracket on your jquery ready function.


you miss closing ); before the tag


You cannot close the <script> tag in the shorthand way you need to use <script></script>. Also the jQuery wrapper needs to be wrapped with

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

or just

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜