1

コンテンツの高さに基づいて、左側のサイドバーの高さを設定する必要があります。これは私が得ているエラーです

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

私はjqueryをロードし、非常に基本的な数行のjsを作成しました:

$(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

4

3 に答える 3

3

$ の代わりに jQuery を使用してこのコードを試すと、動作します。

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

少なくとも、あなたが提供した URL では、このコードを実行すると、サイドバーの高さが等しくないと変更されるようです。

于 2012-10-22T17:42:09.663 に答える
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'"

* $(...) は GLOBAL.Element コレクションのプロトタイプを返すと考えてください

nullはオブジェクトですか?

はい

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')});
});
于 2012-10-22T17:43:34.130 に答える
1

スクリプトの参照に何か問題があります。確認してください。ブラウザのコンソールで関数の jquery メソッドを呼び出せません。コンソールでこれを試してみると、エラーが発生します。

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

ページに含まれて$いないか、別の自由と競合しているため、jQuery ether には参照されません。

于 2012-10-22T17:50:23.210 に答える