2012-10-22 40 views
1

我需要根據內容的高度來設置左邊欄的高度。這是我收到爲什麼左側欄高度不變?

sidebarheight.js:1 Uncaught TypeError: Object # has no method 'ready'

錯誤我已經jQuery的加載,和JS的reeeeally基本幾行:

$(document).ready(function() { 
    $("#left").css({'height':($("#right").height()+'px')}); 
}); 

基本的HTML結構

<div id="left">sidebar content</div> 
<div id="right">page content</div> 

看到工作副本這裏:http://keganquimby.com/122sk

+0

您不應該混合使用像JQuery和Prototype – sdespont

回答

3

如果您使用jQuery而不是$試試這段代碼,它會起作用:

jQuery("#left").css({'height':jQuery("#right").height()+'px'}); 

那麼,至少,在你提供的URL,如果你優秀的代碼側邊欄高度似乎改變,如果他們不相等。

+1

這樣的幾個庫您仍然需要'jQuery.ready(...' – andlrc

+0

是的,當然,需要jQuery.ready,我只是在談論內部代碼。 – sanzante

2

你在你的網站上有原型,它也使用$

嘗試:

jQuery(document).ready(function($) { // This way you have no conflict with the $. In here $ refers to jQuery. All other places $ refers to document.getElementById (From prototype) 
    $("#left").css({'height':($("#right").height()+'px')}); 
}); 

因此,實際上什麼事情是:

$(document) -> document.getElementById(document)* -> null 
-> 
null.ready -> "sidebarheight.js:1 Uncaught TypeError: Object # has no method 'ready'" 

* Think $(...) returns a prototype GLOBAL.Element collection

null是對象?

Yes

alert(typeof null); // object 

而且.....

jQuery(document).ready(...可以短jQuery(...

jQuery(function($) { // This way you have no conflict with the $. In here $ refers to jQuery all other places et's refers to document.getElementById (From prototype) 
    $("#left").css({'height':($("#right").height()+'px')}); 
}); 
1

東西是錯誤的腳本引用,檢查出來,事業瀏覽器的控制檯我無法調用jquery函數的方法,請在控制檯中嘗試此操作,並且會收到錯誤:

var div = $('<div></div>') 
undefined 
div.fadeIn() 
TypeError: Cannot call method 'fadeIn' of null 

$未引用到jQuery以太網,因爲它未包含在頁面中或與另一個自由相沖突。