gpt4 book ai didi

javascript - 删除 ul 标签的连续子代

转载 作者:行者123 更新时间:2023-11-28 12:28:31 25 4
gpt4 key购买 nike

这是我想要操作的 html 片段:

<ul>
<li data-action="CRMEVENTSTREAM" data-parameters="" data-id="3084314321" class="action"><span data-i18n="ui.EVENT_STREAM">Event Stream</span></li>
<li data-action="APPCALENDARVIEW" data-parameters="" data-id="3084314323" class="action"><span data-i18n="ui.CALENDAR">Calendar</span></li>
<li data-action="CRMCUSTOMERSVIEW" data-parameters="" data-id="3084314324" class="action"><span data-i18n="ui.CUSTOMERS">Customers</span></li>
<li data-action="PROFILEEDITDLG" data-parameters="DM_CC" data-id="3084314325" class="action"><span data-i18n="ui.PROFILE_EDITOR">Profile Editor</span></li>
<li class="k-separator"></li>
<li data-action="VIEWCASHMOVEMENT" data-parameters="" data-id="3084314327" class="action"><span data-i18n="ui.CASH_MOVEMENT">Cash Movement</span></li>
<li data-action="CRMAPPLICATIONLIST" data-parameters="" data-id="3084314328" class="action"><span data-i18n="ui.APPLICATION_LIST">Application List</span></li>
<li class="k-separator"></li>
<li data-action="CRMRELATIONEDITOR" data-parameters="" data-id="2998116122" class="action"><span data-i18n="ui.CUSTOMER_RELATION_EDITOR">Customer Relation Editor</span></li>
<li data-action="CRMMULTIRELEDITOR" data-parameters="" data-id="2998116123" class="action"><span data-i18n="ui.MULTIPLE_RELATION_EDITOR">Multiple Relation Editor</span></li>
<li data-action="CRMMASSRELEDITOR" data-parameters="" data-id="2998116124" class="action"><span data-i18n="ui.MASS_RELATION_EDITOR">Mass Relation Editor</span></li>
<li class="k-separator"></li>
<li class="k-separator"></li>
<li class="k-separator"></li>
<li data-action="CRMAPPLICATIONS" data-parameters="" data-id="2998116157" class="action"><span data-i18n="ui.CUSTOMER_APPLICATIONS">Customer Applications</span></li>
<li data-action="CRMCALLLOG" data-parameters="" data-id="2998116187" class="action"><span data-i18n="ui.PHONE_CALLS">Phone Calls</span></li>
<li data-action="CRMCRASEDITOR" data-parameters="" data-id="2998116189" class="action"><span data-i18n="ui.CR_STATUS_EDITOR">CR Status Editor</span></li>
<li class="k-separator"></li>
<li class="k-separator"></li>
</ul>

该 html 是通过来自 Web 套接字的命令动态创建的。但我不希望 li 标签将 k-seperator 类作为 ul 标签的第一个或最后一个子代。而且我也不希望连续的 li 标签具有 k-separator

我的目标是拥有以下 html:

<ul>
<li data-action="CRMEVENTSTREAM" data-parameters="" data-id="3084314321" class="action"><span data-i18n="ui.EVENT_STREAM">Event Stream</span></li>
<li data-action="APPCALENDARVIEW" data-parameters="" data-id="3084314323" class="action"><span data-i18n="ui.CALENDAR">Calendar</span></li>
<li data-action="CRMCUSTOMERSVIEW" data-parameters="" data-id="3084314324" class="action"><span data-i18n="ui.CUSTOMERS">Customers</span></li>
<li data-action="PROFILEEDITDLG" data-parameters="DM_CC" data-id="3084314325" class="action"><span data-i18n="ui.PROFILE_EDITOR">Profile Editor</span></li>
<li class="k-separator"></li>
<li data-action="VIEWCASHMOVEMENT" data-parameters="" data-id="3084314327" class="action"><span data-i18n="ui.CASH_MOVEMENT">Cash Movement</span></li>
<li data-action="CRMAPPLICATIONLIST" data-parameters="" data-id="3084314328" class="action"><span data-i18n="ui.APPLICATION_LIST">Application List</span></li>
<li class="k-separator"></li>
<li data-action="CRMRELATIONEDITOR" data-parameters="" data-id="2998116122" class="action"><span data-i18n="ui.CUSTOMER_RELATION_EDITOR">Customer Relation Editor</span></li>
<li data-action="CRMMULTIRELEDITOR" data-parameters="" data-id="2998116123" class="action"><span data-i18n="ui.MULTIPLE_RELATION_EDITOR">Multiple Relation Editor</span></li>
<li data-action="CRMMASSRELEDITOR" data-parameters="" data-id="2998116124" class="action"><span data-i18n="ui.MASS_RELATION_EDITOR">Mass Relation Editor</span></li>
<li class="k-separator"></li>
<li data-action="CRMAPPLICATIONS" data-parameters="" data-id="2998116157" class="action"><span data-i18n="ui.CUSTOMER_APPLICATIONS">Customer Applications</span></li>
<li data-action="CRMCALLLOG" data-parameters="" data-id="2998116187" class="action"><span data-i18n="ui.PHONE_CALLS">Phone Calls</span></li>
<li data-action="CRMCRASEDITOR" data-parameters="" data-id="2998116189" class="action"><span data-i18n="ui.CR_STATUS_EDITOR">CR Status Editor</span></li>
</ul>

如何使用 jquery 操作 dom?

谢谢

最佳答案

请注意,在删除第一个和最后一个之前,您要先删除相邻的 sibling 。

$('li.k-separator + li.k-separator').remove();
$('li.k-separator:first-child, li.k-separator:last-child').remove();

http://jsfiddle.net/54dd4/

关于javascript - 删除 ul 标签的连续子代,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25062855/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com