2013-05-29 194 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。