大家好,我不是最好的JQuery专家,因此在删除cookie后,我的自定义手风琴无法关闭,这是我手风琴的状态。
我正在使用.Net并创建动态手风琴中继器。
这是我的代码。
<div data-node='<%#XPath ("@no")%>' class=" accordion_head">
<div style="text-align: left;"> <%#XPath ("@date")%>: <%#XPath ("@day")%> </div>
</div>
<asp:Literal ID="litimg" runat="server" />
<div style="padding: 0px; height: 100% auto !important;" class="card card-body accordion_body">
<asp:Repeater ID="childRepeaterToday" runat="server" OnItemDataBound="childRepeaterToday_ItemDataBound" OnItemCommand="_postsRepeater_ItemCommand" EnableViewState="true" DataSource='<%# XPathSelect ("Tour") %>'>
<ItemTemplate>
<div id="ConLuk" class="accordion_container">
<div data-node='<%#XPath ("@no")%>' class='accordion_head' style="width: 100%; padding: 0px;">
<asp:Label runat="server" ID="lblHead" Text='<%# XPath("TourHeaders/TourHeader") %>'></asp:Label>
<i style="margin-right: 10px; float: right;">
<asp:Label runat="server" ID="lblHeadChild" Text='<%# XPath("TourStatus") %>'></asp:Label>
<asp:Label Visible="false" ID="lblIcon" runat="server" />
</i>
</div>
<div class="accordion_body">
<table style="padding: 10px !important;" class="table table-responsive">
<tr>
<tr>
<td>Turnr:
<asp:Label runat="server" ID="lblTourID" Text='<%# XPath("TourID") %>'></asp:Label>
<asp:HiddenField runat="server" ID="lblCustomerPhone" Value='<%# XPath("CustomerPhone") %>' />
<asp:HiddenField runat="server" ID="lblRef" Value='<%# XPath("Reference") %>' />
<asp:HiddenField runat="server" ID="lblLineCount" Value='<%# XPath("LineCount") %>' />
</td>
</tr>
<tr>
<td>
<asp:Label runat="server" ID="lblCustomerName" Text='<%# XPath("CustomerName") %>'></asp:Label>
</td>
</tr>
<tr>
<td>
<%-- <asp:Label runat="server" ID="Label2" Text='<%# XPath("Remarks/Remark") %>'></asp:Label>--%>
<%--<asp:Literal ID="litRemark" Text='<%# XPath("Remark") %>' runat="server" />--%>
<asp:HiddenField Value='<%# XPath("NaviAdr") %>' ID="hdnAdr" runat="server" />
<asp:HiddenField Value='<%# XPath("Longitude") %>' ID="hdnLat" runat="server" />
<asp:HiddenField Value='<%# XPath("Latitude") %>' ID="hdnLng" runat="server" />
<%-- <asp:Repeater ID="rptRemark" runat="server" DataSource='<%# XPathSelect ("Remarks") %>'>
<ItemTemplate>
<asp:Literal ID="litRemark" Text='<%# XPath("Remark") %>' runat="server" />
</ItemTemplate>
</asp:Repeater>--%>
</td>
</tr>
<td>
<div class="btn-group btn-group-justified">
<asp:LinkButton UseSubmitBehavior="false" CommandArgument=' <%#XPath ("TourID")%>' CommandName="accept" class="btn btn-warning" Text="Tilbm" runat="server" />
<asp:LinkButton Target="_blank" class="btn btn-success" CommandName="maps" Text="Navi" ID="lnkBtnMaps" runat="server"></asp:LinkButton>
<asp:LinkButton CommandArgument=' <%#XPath ("TourID")%>' CommandName="info" class="btn btn-info" Text="Info" runat="server" />
</div>
</td>
</tr>
</table>
</div></div>
</ItemTemplate>
</asp:Repeater>
</div>
</div>
</ItemTemplate>
</asp:Repeater>
这是我的Jquery,我试图在单击按钮时重置手风琴。 $(document).ready(function(){
if (document.cookie.indexOf('collapsed_Nodes') >= 0) {
var getCollapsed = Cookies.get('collapsed_Nodes');
var checkCollapsed = getCollapsed.split('|');
var arrayLength = checkCollapsed.length;
for (var i = 0; i < arrayLength; i++) {
$('[data-node="#' + checkCollapsed[i] + '"]').next('.accordion_body').addClass('hide');
$('[data-node="#' + checkCollapsed[i] + '"]').children('.plusminus').children('img').attr('src', './icon/plus.svg');
}
}
var adjustCookie = function() {
var tags = [];
$('.accordion_container .hide').each(function() {
var tag = $(this).prev('.accordion_head').data('node');
tags.push(tag.replace('#', ''));
});
if (tags.length) {
Cookies.set('collapsed_Nodes', tags.join('|'), {
expires: 1,
path: window.location.pathname
});
} else {
Cookies.remove('collapsed_Nodes', {path: window.location.pathname});
}
}
var removeCookie = function () {
if (document.cookie.indexOf('collapsed_Nodes') >= 0) {
var getCollapsed = Cookies.get('collapsed_Nodes');
var checkCollapsed = getCollapsed.split('|');
var arrayLength = checkCollapsed.length;
for (var i = 0; i < arrayLength; i++) {
$('[data-node="#' + checkCollapsed[i] + '"]').next('.accordion_body').addClass('hide');
$('[data-node="#' + checkCollapsed[i] + '"]').children('.plusminus').children('img').attr('src', './icon/plus.svg');
}
}
Cookies.remove('collapsed_Nodes', { path: window.location.pathname });
}
$('.accordion_head').click(function () {
if ($(this).next('.accordion_body').is(':visible')) {
$(this).next('.accordion_body').slideUp(300);
$(this).next('.accordion_body').addClass('hide');
$(this).children('.plusminus').children('img').attr('src', './icon/plus.svg');
} else {
$(this).next('.accordion_body').slideDown(300);
$(this).next('.accordion_body').removeClass('hide');
$(this).children('.plusminus').children('img').attr('src', './icon/minus.svg');
}
adjustCookie();
});
$(function () {
$("#button").click(function () {
//alert('button clicked');
removeCookie();
}
);
});