2011-05-03 43 views
0

啊這個猥瑣的noob我是,下面的html文件不會提醒任何人我的呼救聲。有人知道爲什麼從谷歌加載jquery不起作用(對我來說)

<html> 
<head> 
<script type="text/javascript" 
src="//ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script> 
<script type="text/javascript"> 
    $(document).ready(function() { 
    alert('Somebody please help me.'); 
    }); 
</script> 
</head> 
<body> 
</body> 
</html> 
+0

您正在使用哪種瀏覽器?它是在瀏覽器中打開的獨立.htm文件,在本地主機上測試,Internet託管?)? – 2011-05-03 22:02:09

回答

6

這個工作對我來說:

<html> 
<head> 
<script type="text/javascript" 
src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script> 
<script type="text/javascript"> 
    $(document).ready(function() { 
    alert('Somebody please help me.'); 
    }); 
</script> 
</head> 
<body> 
</body> 
</html> 

script標籤只是固定的src

編輯:實際上,如果您在非本地上下文中加載頁面,原始語法可以正常工作。退出協議意味着將使用「當前」協議,具體取決於是否通過httphttps加載資源。在本地加載它意味着腳本從file:///ajax.googleapis.com/....加載,這顯然不會解決任何問題。有關更多信息,請參閱here。感謝@PetrolMan指向HTML 5鍋爐板網站。

+0

啊...很酷。我從http://encosia.com/2008/12/10/3-reasons-why-you-should-let-google-host-jquery-for-you複製/粘貼該腳本行。我想知道他爲什麼不'沒有「http:」?! – JnBrymn 2011-05-03 21:34:38

+1

如果這修復了它,請將答案標記爲正確... – 2011-05-03 22:04:34

+0

@Sudhir - 我也試過了......它被修復得太快以至於不會讓我接受答案! – JnBrymn 2011-05-04 01:00:16

0

這是

http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js 

//ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js 
0

你缺少在url前面的http:src屬性<script>標籤:

<html> 
<head> 
<script type="text/javascript" 
src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script> 
<script type="text/javascript"> 
    $(document).ready(function() { 
    alert('Somebody please help me.'); 
    }); 
</script> 
</head> 
<body> 
</body> 
</html> 
0

源被擡高向上。使用

src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js" 
3

那相同的語法在使用HTML5鍋爐板:

<!-- Grab Google CDN's jQuery, with a protocol relative URL; fall back to local if necessary --> 
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.js"></script> 
<script>window.jQuery || document.write("<script src='js/libs/jquery-1.5.2.min.js'>\x3C/script>")</script>