2009-09-25 55 views
0

我必須學習JQuery。以下是他們教程中的第一個示例:JQuery - 啓動教程

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

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

    </script> 
    </head> 
    <body> 
    <a href="http://jquery.com/">jQuery</a> 
    </body> 
</html> 

它不起作用。加載頁面後,我沒有看到任何彈出窗口。 我試圖代碼:

window.onload = function() { alert('...'); } 

它的工作原理,但如沒有,爲什麼?

P.S.我已經下載jquery並將其複製到頁面的當前目錄。

回答

1

該代碼看起來不錯。確保jquery.js與html文件在同一個目錄中,並且的確如此命名。所以不是jquery-1.3.2.js或類似的東西。

0

我不知道我們將能夠提供更好的答案。正如所寫的(只要jquery.js文件位於正確的相對位置),代碼應按設計執行。

如果你有懷疑腳本是否是從正確的位置,你可以使用一個CDN提供的腳本拉,所以你知道,它實際上是拉..

<script src="http://ajax.microsoft.com/ajax/jquery/jquery-1.3.2.min.js" type="text/javascript"></script> 
0
<html> 
    <head> 
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> 

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

    </script> 
    </head> 
    <body> 
    <a href="http://jquery.com/">jQuery</a> 
    </body> 
</html> 

這對我的作品。我所做的不同之處在於將jQuery的當前版本與Google Ajax API庫鏈接起來。

試試看。