2016-09-30 42 views
0

我在Web開發領域我試圖我在哪裏幹什麼錯Jquery的適用Google CDN不工作

<!DOCTYPE html> 
<html lang="en"> 
    <head> 
    <meta charset="utf-8"> 
    <meta http-equiv="X-UA-Compatible" content="IE=edge"> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 

    <script type="text/javascript"> 
    google.load("jquery","1.12.4"); 
    google.setOnLoadCallback(function() 
    {console.log($('#title').text()); 
    }); 
    </script> 
    </head> 
    <body> 
     <h1 id="title">Getting Jquery</h1> 
     </body> 
</html> 

回答

1
學習JavaScript我嘗試此代碼來獲得在螢火控制檯消息,但它不工作 請幫助我

如果你想使用jquery,只需在html頭部添加jquery庫並在其上工作即可。

<!DOCTYPE html> 
 
<html lang="en"> 
 
    <head> 
 
    <meta charset="utf-8"> 
 
    <meta http-equiv="X-UA-Compatible" content="IE=edge"> 
 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script> 
 
    <script type="text/javascript"> 
 
     $(function() { 
 
     console.log($('#title').text()); 
 
     }); 
 
    </script> 
 
    </head> 
 
    <body> 
 
     <h1 id="title">Getting Jquery</h1> 
 
     </body> 
 
</html>

0

使用它像下面。

<!DOCTYPE html> 
<html> 
<head> 
    <title></title> 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> 

</head> 
<body> 
</body> 
</html> 

更多版本訪問GOOGLE JQUERY CDN

要檢查它是否工作或沒有做像下面

<!DOCTYPE html> 
 
<html> 
 
<head> 
 
\t <title></title> 
 
\t <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> 
 
\t 
 
</head> 
 

 
<style type="text/css"> 
 

 
</style> 
 

 

 
<body> 
 
<h1 id="title">Getting Jquery</h1> 
 

 

 

 
<script type="text/javascript"> 
 
$(document).ready(function(){ 
 
\t the_h1_text = $("h1#title").text(); 
 
\t alert(the_h1_text); 
 
\t console.log(the_h1_text); 
 
}); 
 

 
</script> 
 

 
</body> 
 
</html>

+0

google.setOnLoadCallback無法正常工作 –