2014-07-07 73 views
0

開始一個新的網站,不能得到任何jQuery的火力。我試過只是在瀏覽器中執行一些控制檯來測試,從外部jquery移動到<head>裏面,並且什麼也得不到。它甚至沒有看到現有的第一個功能。我有一種感覺,這是我忽略的那麼愚蠢簡單的事情,但是我只是從看着相同的< 100行中筋疲力盡。手動獲取寬度時我嘗試的錯誤之一是這樣的。jquery完全沒有開火

Failed to execute 'querySelector' on 'Document': '[object Window]' is not a valid selector."

建議?

<!DOCTYPE HTML> 
<html> 
<head> 
    <script href="http://code.jquery.com/jquery-1.11.1.min.js"></script> 
    <script href="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script> 
    <title>Daniel Jenkins</title> 
    <link rel="stylesheet" type="text/css" href="style.css"> 
    <link href='http://fonts.googleapis.com/css?family=Libre+Baskerville:700' rel='stylesheet' type='text/css'> 
    <script> 
     function set_container_sizes(){ 
      console.log("Setting div sizes"); 
      var window_width = $(window).width(); 
      console.log("Window is "+window_width+"px wide"); 
      var window_height = $(window).height(); 
      console.log("Window is "+window_height+"px tall"); 
      $('#outer_container').css('max-height',window_height+'px'); 
      $('#outer_container').css('max-width',window_width+'px'); 
     } 

     $(document).ready(function(){ 
      console.log("Document now ready"); 
      set_container_sizes(); 
     }); 

     $(window).resize(function(){ 
      console.log("Window resized"); 
      set_container_sizes(); 
     }); 
    </script> 
</head> 
<body> 
    <div id="outer_container"> 
     <div id="inner_top"> 
      <div id="top_head"> 
       Daniel L. Jenkins 
      </div> 
     </div>Hello there  <div id="inner_bottom"> 

     </div> 
    </div> 
</body> 
</html> 
+0

使用'導入JavaScript文件時src',而不是'href'。順便說一句,你的代碼效果很好:http://jsfiddle.net/oscarj24/TM35N/ –

+0

謝謝你,謝謝。我正在計劃一些有趣的事情。就目前而言,這是字面上的,儘管如此。 – TechHeadDJ

回答

7

問題是,您在腳本標記中使用「href」而不是「src」。

+1

我不知道我從哪裏得到那個href,但我現在感覺像是軌道轟炸。謝謝你 – TechHeadDJ

4

我覺得應該是<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>