在数据列表控件中调用jquery函数

时间:2015-01-28 12:17:48

标签: javascript jquery html css asp.net

我想要做什么滑下div并在按钮点击时向上滑动。我在谷歌上搜索直到达到这个结果。问题在于滑动功能不起作用。当我点击按钮div向下滑动但当我再次点击它时不会向上滑动时会发生什么。

 $(function () {
   $(document).on("click", 'a.detials', function (ev) {
     if ($(".shooow").is(":hidden")) {
       $(this).next('div').slideDown('slow');
     }
     else

       $(this).next('div').slideUp('slow');

   });
 });
<asp:DataList ID="dtlRoomsPrice" Visible="false" orizontalAlign="center" runat="server"  ShowFooter="False" ShowHeader="False" Width="700px" OnItemDataBound="dtlRoomsDetails_ItemDataBound">                                                                                         <ItemTemplate>
<a href="javascript:void(0);" class="detials">Show Details</a>                                                                                                     <div class="shooow" id="div_ID" style="width:687px;border-radius: 5px;                                                                                                             box-shadow: 7px 6px 5px #888888; border: 2px solid gray; display:none;padding: 5px; ">

<asp:Label ID="lblAmiintiesTxt" runat="Server" CssClass="shbe_label" Text="<%$ Resources:Resource,Amenities %>" Visible="false"></asp:Label>

<p style="margin-top: 0px;margin-bottom: 0px;font-family: sans-serif; font-weight: bold; font-size: small;">Amenities</p>

<asp:Label ID="lblAmiinties" runat="Server" CssClass="shbe_h2" Text='<%# Eval("Amenities") %>' Visible="true"></asp:Label><br />

<asp:Label ID="lblCanclText" Width="130" runat="server" CssClass="shbe_label" Visible="false" Text="<%$ Resources:Resource, Payment and Cancellation policy %>"></asp:Label>

<p style="margin-bottom: 0px;font-family: sans-serif; font-weight: bold; font-size: small;">CancellationPolicy</p>
 
<asp:Label ID="lblCancelation" runat="Server" CssClass="shbe_h2" Text='<%# Eval("CancellationPolicyText") %>' Visible="true"></asp:Label>
</div>                                                                                             </ItemTemplate>                                                                                      </asp:DataList>

1 个答案:

答案 0 :(得分:0)

您可以简单地使用slideToggle()并简化您的逻辑

$(function () {
    $(document).on("click", 'a.detials', function (ev) {
         $(this).next('div').slideToggle('slow');
    });
});