为什么jQuery不会出现在我的页面中

时间:2012-03-01 03:26:22

标签: javascript jquery

我将“good.html”和“jquery.js”文件放在桌面上名为“jquery2”的文件夹中。

这是我的代码

<!doctype html>
<head>
    <meta charset="utf-8">
    <script type="text/javascript" src="jquery.js"></script>
</head>
<body>
    <script type="text/javascript">
        $(document).ready(function(){
            console.log('ready');
        });
    </script>
</body>
</html>

4 个答案:

答案 0 :(得分:2)

你的

<script type="text/javascript" src="jquery.js"></script>

未引用桌面上的文件。

为了使其工作,您应该将文件上传到服务器。

答案 1 :(得分:1)

您不需要服务器,但您需要在桌面上使用javascript文件的良好路径,如下所示: <script type="text/javascript" src="C:\Users\username\Desktop\jquery2\jquery.js"></script>

在带有Chrome浏览器的Windows 7上为我工作。控制台显示准备好

如果我使路径变坏,控制台会显示“Uncaught ReferenceError:$ is not defined”,然后是旁边的红色X框 获取文件:/// C:/Users/wrongusername/Desktop/jquery2/jquery.js

答案 2 :(得分:0)

它与您的Javascript路径的问题...放在您的代码的相同文件夹或

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js"></script>

更多信息 Where do you include the jQuery library from? Google JSAPI? CDN?

答案 3 :(得分:-1)

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