2013-05-29 141 views
-1

我一直在试图让一个简单的jQuery示例现在工作几个小时。jQuery拒绝工作

<!DOCTYPE html> 
<html> 
<head> 
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"> 
</script> 
<script> 
$(document).ready(function(){ 
    $("button").click(function(){ 
    $("p").toggle(); 
    }); 
}); 
</script> 
</head> 
<body> 

<button>Toggle</button> 
<p>This is a paragraph with little content.</p> 
<p>This is another small paragraph.</p> 
</body> 
</html> 

我似乎无法加载jQuery。

+0

最佳猜想:您没有在您的计算机上安装Web服务器,并且您正在从本地文件系统加载页面,所以jQuery地址中的// //会选择file://协议。这将是学习浏览器错误控制台如何工作的好时机,因此您可以自己调试这样的事情。 – JJJ

+0

您可以在ajax.googleapis.com前删除//然后尝试 – Satya

+0

@Satya这肯定无效。 – JJJ

回答

4

也许,你正在运行本地

你的HTML尝试在jQuery的URL中使用http:这样的 -

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

它似乎缺少HTTP:前缀在脚本网址:

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

http:当你包含javascript:

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

更新这行代码

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"> 

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

添加了https:的SRC。