2012-10-22 42 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以太网,因为它未包含在页面中或与另一个自由相冲突。