Jquery谷歌cdn无法正常工作

时间:2016-09-30 06:43:28

标签: jquery

我在Web Developer领域我正在尝试学习javascript我尝试使用此代码在firebug控制台中获取消息,但它无法正常工作 请帮助我在哪里做错了

<!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>

3 个答案:

答案 0 :(得分:1)

如果你想使用jquery,只需在html的head部分添加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>

答案 1 :(得分: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>
	<title></title>
	<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
	
</head>

<style type="text/css">

</style>


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



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

</script>

</body>
</html>

答案 2 :(得分:0)

尝试在脚本标记中添加JQuery库或CDN,这应该位于Html的标题部分内。

    <head>
    <script src="jquery-1.12.4.min.js"></script>
    </head>

希望它有效。

http://www.w3schools.com/jquery/jquery_get_started.asp

相关问题