在ASP.NET内容页面中选择jQuery id

Ali*_*hşi 1 asp.net jquery content-pages

这是我的脚本:

<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> 
Run Code Online (Sandbox Code Playgroud)

这是我的内容页面:

<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> 
Run Code Online (Sandbox Code Playgroud)

我想选择div_answer显示/隐藏.我写的不是"xxx",我找不到正确的语法.在母版页中,当我写$("#" + answer)它时它起作用.但是,在内容页面中,它不起作用.

Sha*_*oli 5

根据您的标记结构,您可以使用next()它并完成它.next()找到由选择器可选地过滤的紧随其后的兄弟.

$(document).ready(function () { 
    $(".div_question").toggle(function () { 
        $(this).next().slideDown();
    }, function () { 
        $(this).next().slideUp(); 
    }); 
}); 
Run Code Online (Sandbox Code Playgroud)