2014-02-12 36 views
-2

工作,我有下面的代碼裏面的.html:JQuery的不.html文件

<!doctype html> 
<html> 
<head> 
    <title>Test</title> 
</head> 
<body> 
    <div id = "test"></div> 
    <a href="http://jquery.com/"></a> 
    <script src="jquery.js"></script> 
    <script> 
     $("#test").click(function(){ 
      alert("works"); 
     }); 
    </script> 
</body> 
</html> 

然而,當我運行該程序,然後點擊「#TEST」什麼也沒有發生。 我做錯了什麼?

邊注:我使用的崇高文字2

+1

你有沒有加j在head元素中查詢源文件? –

+0

你檢查過提到的Jquery文件的路徑是否正確。 –

+0

用於測試使用jQuery的cdn版本' –

回答

0

你剛纔用jQuery CDN嘗試

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> 
<script> 
$("#test").click(function(){ 
alert("works"); 
}); 
</script> 

這可能有助於你

0

首先檢查你的jQuery的路徑是正確的

<script src="check_your_path/jquery.js"></script> 

<script> 

$(document).ready(function() { 

$("#test").click(function(){ 
alert("works"); 

}); 
}); 

</script> 
0

- 首先你檢查給定的jquery文件的路徑是否正確 - 第二你的div是空的,所以裝上去

<div id="test"> Click Me </div> 

現在它的工作完美

這是我的代碼:

<!doctype html> 
<html> 
<head> 
    <title>Test</title> 
</head> 
<body> 
    <div id ="test">click me</div> 
    <a href="http://jquery.com/"></a> 
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"> 
</script> 
    <script> 
     $("#test").click(function(){ 
      alert("works"); 
     }); 
    </script> 
</body> 
</html> 

和多德始終把你的包含文件像JS,CSS中<head></head> 所以正確的結構是

<!doctype html> 
    <html> 
    <head> 
     <title>Test</title> 
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"> 
    </script> 
<script> 
      $("#test").click(function(){ 
       alert("works"); 
      }); 
     </script> 
    </head> 
    <body> 
     <div id ="test">click me</div> 
     <a href="http://jquery.com/"></a> 


    </body> 
    </html>