0

問題が発生しました。DIV他のすべての を閉じて切り替えようとしています。自分で直そうとしましたが、行き詰まりました。誰かが私が間違っていることを指摘してくれることを願っています。

内でコマンドを実行していませんnot(...)

$(document).ready(function() {
  $('.extralink').click(function() {
    $(this).closest('tr').next('tr.extra').toggle(); 

    $(this).not($(this).closest('tr').next('tr.extra')).hide; 
  });
}

html

    <table class="avs" border="1" width="384px">
        <tr class="avs">
            <th>Avatar name</th>
            <th >Position</th>
        </tr>
        <tr class='avs'>
            <td>
                <a class='extralink' href="#"></a>
            </td>
            <td></td>
        </tr>
        <tr class='extra'>
            <td colspan='2' >
                <div>
                    <div>info</div>
                    <div>image</div>
                </div>
            </td>
        </tr>
 <tr class='avs'>
        <td>
            <a class='extralink' href="#"></a>
        </td>
        <td></td>
    </tr>
    <tr class='extra'>
        <td colspan='2' >
            <div>
                <div>info</div>
                <div>image</div>
            </div>
        </td>
    </tr>
    </table>​
4

2 に答える 2

4

hide 関数に () がありません。これは、実際に呼び出していることを示すために必要です。

$(this).not($(this).closest('tr').next('tr.extra')).hide();
于 2012-08-30T00:41:21.923 に答える
0

もう少し HTML を表示すると役に立ちます。しかし、ここにあなたを助けるためのいくつかの指針があります

$(document).ready(function() {
  $('.extralink').click(function() {
    // should cache the tr
    $(this).closest('tr').next('tr.extra').toggle();     
    $(this).not($(this).closest('tr').next('tr.extra')).hide; //<--missing ()
    // usually not() isn't used with this - as anything with this is usually used inside not() to filter out
  });
}

したがって、このようなものは見栄えが良くなります

$(document).ready(function() {
  $('.extralink').click(function() {
    var $tr = $(this).closest('tr').next('tr.extra');
    $tr.toggle();     
    $('tr.extra').not($tr).hide(); // <-- I'm guessing this is correct
    // since it's these tr's you are looking for to toggle
  });
}
于 2012-08-30T04:06:30.550 に答える