2017-01-24 4 views
-3

コンソールには、このエラーがあります。私は最新のjquery 3.1を使用します。エラーjavascript

この要素を修正するにはどうすればよいですか? window.on

<script>(window).on('load', function(){var maxHeight=0;$(".equal-height").each(function(){if($(this).height()>maxHeight){maxHeight=$(this).height();}});$(".equal-height").height(maxHeight);});</script> 
+9

と同じです。 – Ionut

+0

(ウィンドウ)を$(ウィンドウ)に変更 –

+0

以前にjQueryを使用しましたか? – putvande

答えて

0

あなたはあなたのスクリプトの(window)一部に接頭辞として$を使用する必要は関数ではありませんか、それはjQueryオブジェクトではありません。

例外TypeErrorがありがとう。あなたはあなたのコードの先頭で$シンボルを逃している

<script>$(window).on('load', function(){var maxHeight=0;$(".equal-height").each(function(){if($(this).height()>maxHeight){maxHeight=$(this).height();}});$(".equal-height").height(maxHeight);});</script> 
+1

さらに短くても、 '$(function(){...});'は同じことをします。 – cars10m

-1

、これはjQueryの省略形で、jQueryライブラリのいずれかを使用するときに使用する必要があります。あなたの完全なコードは次のようになります。

$(window).load(function() { 
    var maxHeight = 0; 
    $(".equal-height").each(function() { 
     if ($(this).height() > maxHeight) { 
      maxHeight = $(this).height(); 
     } 
    }); 
    $(".equal-height").height(maxHeight); 
}; 

また、これは、あなたが最初に `$`を逃した

jQuery(window).load(function() { 
    var maxHeight = 0; 
    $(".equal-height").each(function() { 
     if ($(this).height() > maxHeight) { 
      maxHeight = $(this).height(); 
     } 
    }); 
    $(".equal-height").height(maxHeight); 
};