1

これが私のスクリプトです:

<script type="text/javascript"> 
$(document).ready(function () { 
    $(".div_question").toggle(function () { 
        var answer= "answer" + $(this).attr("id"); 
        $("xxx").slideDown(); //  what could i write here.
    }, function () { 
        var answer= "answer" + $(this).attr("id"); 
        $("xxx").slideUp(); 
    }); 
}); 
</script> 

ここに私のコンテンツページがあります:

<asp:Repeater ID="Repeater_question" runat="server" DataSourceID="SqlDataSource_question"> 
 <HeaderTemplate> 
 </HeaderTemplate> 
 <ItemTemplate> 
     <div> 
         <div class="div_question" id='<%# Eval("question_id") %>'> 
               <strong><%# Eval("question_header") %></strong> 
         </div> 
         <div class="div_answer" id='<%# "answer"+Eval("question_id") %>' style="display: none; padding: 5px 5px 5px 15px;"> 
              <%# Eval("question_content") %> 
         </div> 
     </div> 
 </ItemTemplate> 
</asp:Repeater> 

div_answer表示/非表示を選択したい。「xxx」の代わりに書いたものですが、正しい構文が見つかりません。マスターページでは、私が書く$("#" + answer)とうまくいきます。しかし、コンテンツページでは機能しません。

4

1 に答える 1

5

マークアップ構造に基づいて、使用するだけnext()で完了できます。next()オプションでセレクターによってフィルタリングされた直後の兄弟を検索します。

$(document).ready(function () { 
    $(".div_question").toggle(function () { 
        $(this).next().slideDown();
    }, function () { 
        $(this).next().slideUp(); 
    }); 
}); 
于 2012-03-31T23:55:30.603 に答える