1

私は、開いたり、最小化したり、閉じたりするデスクトップ スタイルのアプリケーション ウィンドウを模倣するアプリケーションに取り組んでいます。それらを展開したり折りたたんだりすることはできましたが、閉じることができず、その理由がわかりません。ボタンをクリックして現在の div を閉じることができるようにする必要があります。コード/例を参照してください。下。

<script>
     $(document).ready(function () {

        $("form.common").first().show();
             $(".expand").click(function () {
                 $(this).parents().next("form.common").show();
             })
             $(".collapse").click(function () {
                 $(this).parents().next("form.common").hide();
             });
             $(".close").click(function () {
                 $(this).parents().next("div.module").hide();
             });
    });
 </srcipt>
 <div id="task_manager" class="module"> <!-- Need the x with class close to hide this div-->
 <h3>Task Manager</h3> <!-- This header and below icons are shown when minimized-->
<div class="module_actions">
    <span class="icons_small right close">X</span>
    <span class="icons_small right collapse">-</span>
    <span class="icons_small right expand">+</span> 
</div>  
<form class="common">
    <fieldset>
     <legend> Some Titlee/legend>
    </fieldset>
</form>
</div>

なぜこれがdivを隠していないのか、誰にもわかりますか? ありがとう、

4

3 に答える 3

3

答えは質問にあります:

$(".close").click(function () {
    $(this).closest("div.module").hide();
});

デモフィドル

また、呼び出しをparents()に変更parent()して、DOM ツリーの 1 レベル上に移動する必要があります。

于 2013-09-21T18:47:46.703 に答える
0

これはうまくいくはずです:

  $(".close").click(function () {
       $(this).parent().hide();
   });

JSFiddle
Doc : 親()

于 2013-09-21T18:42:42.693 に答える