$(文件).还没有解雇?

Han*_*nna 6 jquery

这么简单的代码,为什么不工作?页面加载时,它应显示一个"就绪"的警告框.

<!DOCTYPE html>
<html>
    <head>
        <title>
        Title
        </title>
        <script type="text/javascript">
            $(document).ready(function() {
                alert("ready");
            });
        </script>
    </head>
    <body>
        Content
    </body>
</html>
Run Code Online (Sandbox Code Playgroud)

我觉得这是非常明显的事情,但我正处于一个我无法思考的地步.

我在最新版本的Chrome和Firefox中都试过了.

ork*_*Bad 29

你的jquery ref在哪里?

        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
Run Code Online (Sandbox Code Playgroud)

  • *facepalm*哇. (11认同)
  • facepalm确实. (7认同)
  • 我在想,你知道有什么好笑的吗?我复制的 [source](http://jquery.com/)。 (2认同)

xr2*_*0xr 12

我有这个问题,但引用了jQuery.在将javascript移动到外部文件时,我不小心将前一个脚本标记写为自闭标记:

<script type="text/javascript" src="/wherever/whatever.js" />
<script type="text/javascript">
    $(document).ready(function(){ /* not hit */ });
</script>
Run Code Online (Sandbox Code Playgroud)

外部参考标签不能自动关闭.它应该读<script type="text/javascript" src="/wherever/whatever.js"></script>