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

标签 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>

最佳答案

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

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

关于javascript - 在数据列表控件中调用 jquery 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28192072/

相关文章:

javascript - 2 个数组之间的匹配值必须将选项 HTML 设置为禁用

php - 使用 input[type ="file"] 提示用户保存文件

javascript - 尝试让 div 在按下按钮时淡入过渡时间和延迟,但无法在显示 :none and display:inline? 之间切换动画

javascript - InsertAdjacentHTML,元素刷新后保存

javascript - 如何使用 WSDL 实用程序生成的 JavaScript 类?

javascript - 滚动时尝试使用 jquery 使内容淡入

javascript - 在复选框按钮选项列表上应用 css 规则

javascript - 主干 View 事件或冒泡

jquery - Chrome 淡入滚动条问题

html - 如何在不发生换行的情况下将按钮放入文本中?