我的测试网站缺少JQuery源文件?

时间:2012-06-09 12:41:24

标签: jquery

我在w3schools.com上测试了以下代码;但是,当我在我的本地机器上试用它时它不起作用。我有一种感觉,原因是我没有文件jquery.js。我当时认为它只是jquery脚本声明的一部分而已。用jquery.js写的是什么?我可以包含替代文件吗?

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $("button").click(function(){
    $(this).hide();
  });
});
</script>
</head>

<body>
<button>Click me</button>
</body>
</html>

2 个答案:

答案 0 :(得分:1)

W3Schools链接到称为jquery的常见JavaScript库。您需要将其本地下载并存储到您的站点以便您可以引用它,或者您可以使用gooole api版本:ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>

答案 1 :(得分:1)

您可以更改此行

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

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>

将从谷歌CDN(内容分发网络)加载jQuery库。还有其他几个CDN,请查看此处的列表http://docs.jquery.com/Downloading_jQuery#CDN_Hosted_jQuery

或者

在浏览器中加载https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js并将文件jquery.js保存在上述文件所在的目录中,您的代码将正常运行。

查看本教程以获取更多详细信息http://docs.jquery.com/How_jQuery_Works