2013-12-11 29 views
0

我已經使用bob tabors jQuery視頻教程here很長一段時間了,我無法讓jQuery工作。jQuery不適用於新手

這裏是我的html

<!DOCTYPE html> 
<html> 
<head> 
<script type="text/javascript" src="jquery.js"></script> 
<script type="text/javascript" src="script.js"></script> 
    <link rel="stylesheet" type="text/css" href="main.css" /> 
    <title>14. Getting Started with jQuery</title> 
</head> 
<body> 
    <h1 id="title">14. Getting Started with jQuery</h1> 

    <p id="first"> 
    <span>Now is the time for all good men to come to 
      the aid of their country.</span> 
    </p> 

    <p id="second"> 
    <strong>In the end these things matter most: 
     How well did you love? How fully did you live?</strong> 
    </p> 

    <p id="third"> 
    <a id="myAnchor" href="http://www.learnvisualstudio.net">Visit my website</a> 
    </p> 

</body> 
</html> 

這裏是我的js

jQuery(document).ready(function() { 
alert("thsdjasl"); 

} 

但HTML後,毫無戒備來。

+0

是'jquery.js' jQuery源代碼還是您在問題底部顯示的js? –

+3

檢查你的控制檯...你錯過了一個');' – Syjin

回答

10

你缺少右括號您準備功能:

jQuery(document).ready(function() { 
    alert("thsdjasl"); 
}); 

沒有這個您的警報將不會運行,您將收到以下錯誤:

Uncaught SyntaxError: Unexpected token }

+0

Thnx很多,很快就會接受 –

-2

確保目錄根目錄中的jquery.js文件。並使用此:

$(document).ready(function(){ 
    console.log('bla bla '); 
    alert('bla'); 
}); 
+0

IT與其他文件相同 –

0

您錯過了一個結束括號和分號。理想情況下,您應該使用文件準備好的「$」命名法:

$(document).ready(function() { 
    alert("thsdjasl"); 

});

最後,您可以通過在瀏覽器中打開開發人員工具(Chrome瀏覽器很好),轉到javascript源選項卡並查找彈出的錯誤和警告來了解這一點。