0

誰でも私を助けることができますか、エラーがどこにあるのかわかりません。

これは私のjQueryです:

function altezzadotgrey(){
    $('.views-field-title').each(function(){
        var aaltezzadotgrey = $(this).outerHeight();
        if ($(this).outerHeight() > 40) {
            $(this).css("margin-top", "-45px");
        }
    });
}

これは私のHTMLです:

<div class="views-row">
    <div class="views-field-title">
        <span class="field-content"><a href="">a</a></span>
    </div>
</div>
<div class="views-row">
    <div class="views-field-title">
        <span class="field-content"><a href="">b</a></span>
    </div>
</div>
<div class="views-row">
    <div class="views-field-title">
        <span class="field-content"><a href="">c</a></span>
    </div>
</div>
<div class="views-row">
    <div class="views-field-title">
        <span class="field-content"><a href="">d</a></span>
    </div>
</div>

に問題がある可能性があると思いますeach()

4

3 に答える 3

1

jQuery.css は CSS スタイルではなく「DOM スタイル」プロパティを使用するため、次のようにします。

$(this).css("marginTop", -45);

ここを参照してください:http://jsfiddle.net/4upSX/1/

実際には「margin-top」でも機能します...「.views-field-title」が実際に 40px を超えていることは確かですか?

于 2013-01-09T11:29:06.437 に答える
0
function altezzadotgrey(){

  $('.field-content').each(function(){

        var h= $(this).css('height');
        if (parseInt(h)  > 40) {
            $(this).css("margin-top","-45px"); 
        }
    });
 }
于 2013-01-09T11:10:51.313 に答える
0

ボディロードで関数を呼び出すだけです

$( function() {    
    altezzadotgrey();    
});

function altezzadotgrey(){
    $('.views-field-title').each(function(){
        var aaltezzadotgrey = $(this).outerHeight();
        if ($(this).outerHeight() > 40) {
            $(this).css("margin-top", "-45px");
        }
    });
}

それ以外はすべて正しい

于 2013-01-09T11:46:50.767 に答える